• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Basheer Yunus
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Sunil Chandurkar
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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: 37
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic