• 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

out.print("How to display an Image")

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Masters

I want to use out.print("<img src=...>") in servlet of a package.
I want to know where the images should be stored and how can I give the image path in src=...
Is there any special considerations while using a jpeg file to display using out.print("<img src=...>")

Kindly help
[ August 31, 2008: Message edited by: Basheer Yunus ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can be anywhere in the web app outside of the WEB-INF folder. See the JSP FAQ for an entry on properly creating URLs to such resources.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basheer,

I would use a JSP page for this.

For example, in a JSP page called "images.jsp".

<html><body>

<img src="/image1.jpg" >

</body></html>

The image in this case resides inside the root directory of your application.
For example E:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.16\webapps\examples\image1.jpg. "examples" being the name of your web application.

In your servlet code:

RequestDispatcher rd = request.getRequestDispatcher("/images.jsp");
rd.forward(request,response);

For simplicity I would put the images.jsp page in the "examples" folder.

Hope this helps

Sunil
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sunil Chandurkar:
For simplicity I would put the images.jsp page in the "examples" folder.


No. Bad idea! Do not mix resources for your web application with the examples provided by Tomcat.
 
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

Originally posted by Bear Bibeault:

No. Bad idea! Do not mix resources for your web application with the examples provided by Tomcat.



Dear Bear,

Please let me know about the problems that I can face if I implement Sunil's Idea .

Thanks
 
Sunil Chandurkar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basheer,
Bear is right the name "examples" caused confusion, I meant save the "images.jsp" in the root directory of your application. Say, the name of your application's root directory is beer, then we can save "images.jsp" in the "beer" folder.
 
reply
    Bookmark Topic Watch Topic
  • New Topic