-
Applet Servlet Communication on Weblogic81
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
Similar Threads
-
By rickstrong in forum Java
Replies: 2
Last Post: 04-02-2007, 05:58 PM
-
Replies: 1
Last Post: 01-07-2006, 11:07 AM
-
Replies: 1
Last Post: 08-10-2000, 12:35 PM
-
Replies: 1
Last Post: 08-10-2000, 12:33 PM
-
Replies: 1
Last Post: 05-26-2000, 11:11 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks