This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes out.print( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "out.print("How to display an Image")" Watch "out.print("How to display an Image")" New topic
Author

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

Basheer Yunus
Greenhorn

Joined: Dec 24, 2007
Posts: 7
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

Joined: Jan 10, 2002
Posts: 60748
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sunil Chandurkar
Ranch Hand

Joined: Jan 09, 2008
Posts: 37
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

Joined: Jan 10, 2002
Posts: 60748
    
  65

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

Joined: Dec 24, 2007
Posts: 7
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

Joined: Jan 09, 2008
Posts: 37
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: out.print("How to display an Image")
 
Similar Threads
How to display an image file to jsp
Disabling an image
displaying image + JSP
img tag does not display image
Storing, retrieving, displaying images