wood burning stoves 2.0*
The moose likes Servlets and the fly likes Image issue with Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Image issue with Servlet" Watch "Image issue with Servlet" New topic
Author

Image issue with Servlet

Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Dear All,

I am using following code that calls the servlet that in turn sets the output stream to the response. and my image src calls the servlet and it should display the chart. But it is not happening. It does call the servlet but it is not displaying the image. Can any one tell me where am i mistaking.



Servlet
-------------------------------------------------------------
OutputStream out = businessObj.getChart(inputMap);

res.getOutputStream().write(outputStream.toByteArray());
-----------------------------------------------------------
Jsp
-----------------------------------------------------------
url= request.getContextPath() +"/chart?current="+date;
<img src="<%=url%>" align="right" border="1" />



Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41865
    
  63
Have you tried writing the contents of the output stream to a file, or the console, to make sure it contains the correct output?


Ping & DNS - my free Android networking tools app
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
1. are you setting the response content-type correctly?
2. are you setting the response content-length correctly?
3. what does the URL for the request look like?

Bill
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Originally posted by William Brogden:
1. are you setting the response content-type correctly?
2. are you setting the response content-length correctly?
3. what does the URL for the request look like?

Bill

it was working fine earlier.We changed our project hierarchy and switched to tomcat 5.5.25. I dont know what happened to it now. all was working well before it.

2. i did not get this question.I am not aware about how to set content-length in response. i have not set any such variable.
3. it is /appname/servletname?current=Tue Jul 01 09:39:20 EDT 2008.but it was earlier /servletname?current=Tue Jul 01 09:39:20 EDT 2008.but if it is able to hit the servlet inspite of the changed url, how did it start malfunctioning
[ July 01, 2008: Message edited by: Patricia Samuel ]
Siddharth Naik
Ranch Hand

Joined: Apr 09, 2006
Posts: 35
I am not aware about how to set content-length in response


res.setContentLength(myByteArrayOutputStream.size());


Thanks<br />Sid
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
The reason I suggest setting the content-length is that browsers are sometimes picky about interpreting binary data without it.

Another possible problem occurs to me - are you closing the output stream after writing the image data to it? The last buffer load of data may be just sitting there.

Bill
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Thanks William .

I found the reason. It was working earlier fine. But there is problem with jfreechart 1.0.9 version. it does not support JPEG image properly. Hence i changed to PNG.Now its working fine.



Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image issue with Servlet