Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display JPEG file using Servlet

 
Basheer Yunus
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frnds,

I have created a Bar Chart using Jfreechat, the Bar Chat is a jpg file, Now I want to display this jpg file in browser. I am using <img src > tag for displaying jpg file in servlet but it is not displaying the jpg file always (I am using NetBeans 5.5).
[I have two files bar_chart3D.jpg & bar_chart.jpg - it is displaying the jpg when I give the src as bar_chart3D.jpg but not displaying jpg when I give bar_chart.jpg, I dont know the reason.]

I request masters to help me to display jpg files using servlet.

Thank you
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using the correct URLs when accessing those images? Are the permissions on the files set to allow public access?

You can start to diagnose the problem by using a tool like the LiveHttpHeaders extension for Firefox; it displays all image requests sent by the browser as well as the server's response.
 
Basheer Yunus
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just running my servlet in netbeans which opens IE and displays the jpg file. I have placed the jpg file in the same directory where the servlet is residing (same package).

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<HTML><BODY>");
out.print("<img SRC=\"bar_chart.jpg\" ALT=\"Bar Chart\">");
out.println("</BODY>");
out.println("</HTML>");
.....
}


if I give bar_chart3D.jpg then it is displaying. So that means it may not be a problem with permissions.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An image needs to be in a publicly accessible directory, not in whatever directory the servlet code or classes are in. I'd advise to set up and test the web app outside of any IDE. Then it should become clear quickly what the problem is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic