Forums Register Login

Displaying images

+Pie Number of slices to send: Send
This is strange to me. I have a new JSP project with images that reside in an 'images' folder within the WEB-INF folder. Although the path to the images is correct (i.e., src="/images/companyLogo.jpg") none of the images display. Does anyone have any ideas about this?
+Pie Number of slices to send: Send
I would check following things.
1. Images should not be behind WEB-INF, because servlet container protects WEB-INF. Put images in the same directory as your html/jsp in images subdirectory.
2. When servlet container runs, its path is where you started it ( <tomcat>/bin directory for tomcats ). You will need to use real path ServletContext.getRealPath() method to get real path to web application and add your location behind WEB-INF.
3. If you have a lot of images which are accessed from html, I would setup web server, such as apache to get them. This will improve performance of you web application. Don't map apache to look behind WEB-INF, because you will create a security breech in your web application.
+Pie Number of slices to send: Send
Your images should not sit under the WEB-INF folder unless they are used on the server side using the getResource or getResourceAsStream APIs.
Put the images folder in the root of your application directory and then they should display.
Cheers
There's a way to do it better - find it. -Edison. A better tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1088 times.
Similar Threads
Dispaly all images of folder
Question about package
JSP javascript images slideshow problem
Call an image from another package
Where to store uploaded pictures?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:26:43.