Hi,

I am trying to send image data from applet to servlet.
Code snippets are:

Applet class:

//...........
ByteArrayOutputStream baos = new ByteArrayOutputStream();

try {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
encoder.encode(img);
int contentLength = baos.size();
//calling servlet...........
URL toServlet = new URL("http://" + host + ":" + port + "/vcm_gallery/image/test?imageId=" + imageId + "&imageSrc=" + imageSrc + "&imageFileName=" + imageFileName);
URLConnection servletConnection = toServlet.openConnection();
servletConnection.setDoInput(true);
servletConnection.setAllowUserInteraction(true);
servletConnection.setDoOutput(true);
servletConnection.setRequestProperty("Content-Length", "" + contentLength);
OutputStream outputToServlet = servletConnection.getOutputStream();
baos.writeTo(outputToServlet);
//outputToServlet printed the binary content on the console
System.out.println("Output servlet:"+outputToServlet);
servletConnection.connect();
//.............
// host & port are I am getting correct values

//..........................servlet code

ServletInputStream ois = httpServletRequest.getInputStream();
String imageId = httpServletRequest.getParameter("imageId");
String imageFileName = httpServletRequest.getParameter("imageFileName");
String realPath = getServletContext().getRealPath("");
String imageSrc = httpServletRequest.getParameter("imageSrc");
realPath = realPath + "/images/" + imageFileName;
byte[] byteArr = new byte[2048];
int read = -1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
while ((read = ois.read(byteArr)) != -1) {
baos.write(byteArr);
}
// here, written the image to database.......
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}

//................

It is working fine on Tomcat5.0/5.5. But on weblogic81, image saved in the database is null...
I have used the debug options, ois.read() value in the servlet class returning -1, so in the database the image inserted is null(0 bytes).


Please help me in this regard, if you have known. It is urgent.


thanks in advance
Suraj