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 ?
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?
Ping & DNS - updated with new look and Ping home screen widget
Joined: Nov 26, 2008
Thank you for your reply, I stored all the images outside the application.Not in the Application.
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.
... 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.
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.
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.
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 ]