|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by esko_user in Java Server Pages (JSP)
Hi,
I have a JSP that invokes an applet. This applet creates an Buffered Image, I need to pass this buffered image to a servlet that is hosted on the same web server as the JSP, this servlet is supposed to create a file from the BufferedImage and then upload to a location on the same web server. I am facing a problem in the communication between the Applet and Servlet. The servlet is not even getting called..!!
Could you please tell me what I am missing, following is the code snippets that I am using
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
|
JSP:
<body>
<applet code="Applet.class" archive="Applet.jar"width="300" height="300"/>
</body>
Applet:
public void sendBufferedImage(String urlpath, BufferedImage image) {
try {
System.out.println("Sending the image data");
URL url = new URL(urlpath);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStream out = conn.getOutputStream();
ImageIO.write(image, "jpg", out);
out.close();
System.out.println("Sent the data to " + url);
} catch (IOException ex) {
ex.getMessage();
}
}
Servlet:
System.out.println("getting the image from applet");
File filename = new File(getServletContext().getContextPath() + "test.jpg");
FileOutputStream outy = new FileOutputStream(filename);
InputStream in = request.getInputStream();
byte[] buf = new byte[256];
int nread = 0, total_read = 0;
while (-1 != (nread = in.read(buf))) {
total_read += nread;
outy.write(buf, 0, nread);
}
System.out.println("bytes read " + total_read);
out.close();
|
20091118-EE-VQP-93 - Hierarchy / EE_QW_Related_20080208