• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display JPEG file using Servlet

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic