Click here to Skip to main content
15,910,980 members
Home / Discussions / Java
   

Java

 
GeneralRe: Code Help! Pin
Richard MacCutchan19-Jul-15 21:54
mveRichard MacCutchan19-Jul-15 21:54 
QuestionJava8 installer doesn't start w/o any messages Pin
moonwalker7206715-Jul-15 20:27
professionalmoonwalker7206715-Jul-15 20:27 
AnswerRe: Java8 installer doesn't start w/o any messages Pin
Richard MacCutchan15-Jul-15 21:40
mveRichard MacCutchan15-Jul-15 21:40 
QuestionJAVA Pin
Member 1183525613-Jul-15 20:24
Member 1183525613-Jul-15 20:24 
AnswerRe: JAVA Pin
Richard MacCutchan13-Jul-15 22:17
mveRichard MacCutchan13-Jul-15 22:17 
QuestionSales Tracking Assignment & Unfinished Code Pin
Member 1072866711-Jul-15 14:42
Member 1072866711-Jul-15 14:42 
QuestionRe: Sales Tracking Assignment & Unfinished Code Pin
Richard MacCutchan11-Jul-15 21:56
mveRichard MacCutchan11-Jul-15 21:56 
QuestionThe Use Of Webcam To Capture Image And Video Streaming Pin
goddynk8-Jul-15 1:28
goddynk8-Jul-15 1:28 
Please in course of my search for a java web application that uses a Webcam to make a stream of video clip and with the capability of snapping image in course of the video streaming process I came across this link: http://www.webdesignermag.co.uk/capture-webcam-video-with-html5/
I realized that the program suits my need but it does not have a way of programmatically giving the video and or the captured image a unique name and a directory where they can be saved respectively. Therefore I tried to modify the index.jsp, web.xml and the ImageServlet.java codes to be able to programmatically give the video and the captured image a unique name and consequently save them in the C:/WebcamAccess directory but I had no luck. Instead I had the following output: messageHTTP method GET is not supported by this URL descriptionThe specified HTTP method is not allowed for the requested resource.
My request therefore is that you assess my work to see what I am getting wrong and correct me. I am not so proficient with java web and Netbean IDE. The attached are the work I have done so far


Index.jsp Codes:
HTML
<!DOCTYPE html>
&lt;head>
&lt;title>Web Cam Access&lt;/title>
&lt;script src="http://code.jquery.com/jquery-1.7.2.min.js">&lt;/script>
&lt;script type="text/JavaScript" src="jquery. webcam.min.js">&lt;/script>
&lt;/head>
&lt;body>
<video autoplay></video>
&lt;form>&lt;input type='button' id='capture' value="Capture Image!"/>&lt;/form>
<div id="webcam"></div>
<p><a href="javascript:webcam.capture();void(0);">
</a></p>
&lt;script type="text/javascript">
jQuery("#webcam").webcam({
width: 320,
height: 240,
mode: "callback",
swffile: "jscam.swf",
});
&lt;/script>
<canvas id='canvas' width='150' height='170'></canvas>
&lt;script language='javascript'>
document.getElementById('capture').onclick = function () {
var video = document.querySelector('video');
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, 300, 250);
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
// for (n = 0; n < data.width * data.height; n++) {
// var index = n * 4;
// data.data[index + 0] = 255 - data.data[index + 0];
// data.data[index + 1] = 255 - data.data[index + 1];
// data.data[index +`` 2] = 255 - data.data[index + 2];
// }
ctx.putImageData(data, 0, 0, canvas.width, canvas.height);
/*
* HttpRequest is used to send the image to the ImageServlet
* by the following codes...
*/
var imgData = canvas.toDataURL();
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "/WebcamAccess/capture", true);
xmlhttp.send(imgData);
}
&lt;/script>
&lt;script src="webcam.js">&lt;/script>
&lt;/body>
&lt;/html></pre>

<pre lang="xml"><u>Web.xml Code:
</u>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<description>Image Capture Tutorial</description>
<display-name>Tutorial</display-name>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<!-- Servlet -->
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>controller.ImageServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/capture</url-pattern>
</servlet-mapping>
</web-app>


ImageServlet Code:
Java
package controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.Reader;
//import java.util.Random;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sun.misc.BASE64Decoder;
public class ImageServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
        try {
            StringBuffer buffer = new StringBuffer();
            Reader reader = request.getReader();
            int current;
            while ((current = reader.read()) >= 0) {
                buffer.append((char) current);
            }
            String imgName;
            imgName = "abc";
            String data = new String(buffer);
            data = data.substring(data.indexOf(",") + 1);
            System.out.println("PNG image data on Base64: " + data);
            FileOutputStream output = new FileOutputStream(new File("/C:/WebcamAccess/"
            + imgName + ".png"));
            output.write(new BASE64Decoder().decodeBuffer(data));
            output.flush();
            output.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}


modified 8-Jul-15 7:50am.

Questioni want to solve this probelem. pls help me. Pin
Member 118168846-Jul-15 3:56
Member 118168846-Jul-15 3:56 
GeneralRe: i want to solve this probelem. pls help me. Pin
PIEBALDconsult6-Jul-15 4:32
mvePIEBALDconsult6-Jul-15 4:32 
AnswerRe: i want to solve this probelem. pls help me. Pin
Richard MacCutchan6-Jul-15 5:30
mveRichard MacCutchan6-Jul-15 5:30 
AnswerRe: i want to solve this probelem. pls help me. Pin
Member 117346789-Jul-15 1:37
Member 117346789-Jul-15 1:37 
QuestionJava course Pin
Member 118100102-Jul-15 16:54
Member 118100102-Jul-15 16:54 
QuestionRe: Java course Pin
Richard MacCutchan2-Jul-15 21:19
mveRichard MacCutchan2-Jul-15 21:19 
AnswerRe: Java course Pin
vicsepu20036-Jul-15 9:58
vicsepu20036-Jul-15 9:58 
QuestionMessage Closed Pin
1-Jul-15 15:02
CptDanko1-Jul-15 15:02 
AnswerRe: Making iOS apps like making a Java web app Pin
Richard MacCutchan1-Jul-15 21:21
mveRichard MacCutchan1-Jul-15 21:21 
GeneralRe: Making iOS apps like making a Java web app Pin
CptDanko1-Jul-15 23:29
CptDanko1-Jul-15 23:29 
QuestionJava Pin
LysiasTJ30-Jun-15 23:33
professionalLysiasTJ30-Jun-15 23:33 
AnswerRe: Java Pin
Richard MacCutchan1-Jul-15 0:25
mveRichard MacCutchan1-Jul-15 0:25 
QuestionJquery slideshow Pin
vikkismarty29-Jun-15 4:56
vikkismarty29-Jun-15 4:56 
AnswerRe: Jquery slideshow Pin
Richard MacCutchan29-Jun-15 5:08
mveRichard MacCutchan29-Jun-15 5:08 
Questionjava programming Pin
vikkismarty29-Jun-15 1:15
vikkismarty29-Jun-15 1:15 
AnswerRe: java programming Pin
Richard MacCutchan29-Jun-15 3:38
mveRichard MacCutchan29-Jun-15 3:38 
GeneralRe: java programming Pin
vikkismarty29-Jun-15 4:55
vikkismarty29-Jun-15 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.