I want to grab an image from my USB web-cam after a button click in a jsp page. I have already shown my live web cam in the jsp page but I want to store it in a folder. I want that output from the jsp page after the button click to be stored in a folder
Asked
Active
Viewed 242 times
-1
-
1JSP runs on the server and has no access to client (browser) side hardware. You have to use some JavaScript or other client-side code to capture an image, and then send the acquired picture to the server over HTTP. – Jozef Chocholacek Aug 05 '19 at 06:52
-
yes,but how to use javascript over it? – VISHAL JADHAV Aug 05 '19 at 10:04
1 Answers
-1
First add hidden field for image data in Jsp: -
<input type="hidden" name="ImageData" id="ImageData"/>
second through java script add image data in it :-
document.getElementById('ImageData').value = canvas.toDataURL("image/png");
third : Fetch value in servet using request: -
String imageData = request.getParameter("ImageData");
fourth :- convert it to inputstream :-
byte[] imagedata = DatatypeConverter.parseBase64Binary(imageData.substring(imageData.indexOf(",") + 1));
BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imagedata));
ImageIO.write(bufferedImage, "png", new File("img.png"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());**

Jozef Chocholacek
- 2,874
- 2
- 20
- 25

VISHAL JADHAV
- 1
- 2
-
The question is asking how to capture data from a webcam, not a canvas element. – Quentin Aug 05 '19 at 10:57