• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Jsp retrieve Image

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I am working on linux environment and using Netbeans5.5.I put all the Images outside the Application,While i use
<img src="/home/MyHomeGallery/image1.jpg"> its not getting the images.
Can you plse suggest me ?
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did following steps to achieve this:

1- Create a xml file under
<jakarta-tomcat>\conf\Catalina\localhost
mine is resourceContext.xml
Content of this file is:


2- under G:/images create WEB-INF directory

3- Restart the server

Now you can access a image from your JSP page like:
<img src ="/resourceContext/image1.jpg"/>


Does this work for you?
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that image paths are relative to the web root. A path like "/home/MyHomeGallery/image1.jpg" will cause the image to be looked for at "http://www.my-server.com/home/MyHomeGallery/image1.jpg" - is that where the image is located?
 
KedariNadh vsilla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply,
I stored all the images outside the application.Not in the Application.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you expect your web server to serve these images they will have to be in a directory structure the server is allowed to access - and - the URL will have to reflect the way the server finds files, NOT the way the operating system finds them.

Bill
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Try to use fmt or core jstls tags for this, instead of <img> tag.

Once check the below link also, it may help you.

http://forums.sun.com/forum.jspa?forumID=427


ThankYou,
Subrahmanyam Baratam,
WebSphere PortalDeveloper.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Subrahmanyam Baratam:

... Try to use fmt or core jstls tags for this, instead of <img> tag. ...



If the images are not stored in a place where they would be accessible to the web, fmt and JSTL tags will not help.

If you can't move the images to a location within your application's directory structure, you will need to write a servlet that reads the files in their current location and streams them to the browser.

We have a similar servlet in our CodeBarn.
http://faq.javaranch.com/java/CodeBarnSimpleStream

You'll need to change it a little as the example uses getResourceAsStream to read the file from under the WEB-INF directory. You'll want to use java.io.File to read the file if it's not stored within your application's directory structure.
 
Subrahmanyam Baratam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben, if there are number of images to displayed onto the page, then reading each image as a stream and displaying it wont't affect the performance.

If the performance won't affect its better to follow your code.I hope it will lead to a performance issue. Please reply.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is, for the most part, what the container would do if your images were within your web app and requested directly.
Take a look at the code to Tomcat's DefaultServlet to see how it handles requests for static resources.

http://svn.apache.org/repos/asf/tomcat/container/tc5.5.x/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java

There is a lot more to sift through but when it comes down to it, it's doing the same thing:


Newer versions or other containers might be using nio to speed things up.
You also won't be able to take advantage of any caching capability unless you write your own.

Lastly, if you want to speed up performance for images that are requested frequently by the same user, you might want to add code to check the if-modified-since request header, compare that with the timestamp of the file and return the proper header instead of the entire image with each request.

Again, if you can move the images into your webapp, the container will do all of this for you.
[ November 27, 2008: Message edited by: Ben Souther ]
 
Subrahmanyam Baratam
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for clearing the doubt Ben.
reply
    Bookmark Topic Watch Topic
  • New Topic