| Author |
Referencing images in a servlet
|
Larry Homes
Greenhorn
Joined: Jan 18, 2009
Posts: 25
|
|
Hello,
The image is located in $TOMCAT_HOME/webapps/test/WEB-INF/resources. In a servlet, I have an org.w3c.dom.Element made that will be an image node. After setting the src attribute of the Element, I append it to the html page the servlet is parsing and print the page out.
I have experimented with a couple of paths to put in the src attribute, but none of them find the image. I know its not a problem with my syntax of the appending of the node, because the img tag in the page shows up in the right place and has the correct syntax. Its just that it cannot find the image with any of the paths I try for the src sttribute.
So how would I reference this image? What path should I use?
|
 |
Gopikrishna Kunisetty
Ranch Hand
Joined: Jun 12, 2008
Posts: 35
|
|
Try moving the images location from WEB-INF/resources to some thing which is on the same line as WEB-INF. The reason is ,WEB-INF directory
is a 'special' one; anything under it is not to be served directly to web clients.
|
- Krishna<br /> SCJP 1.4 SCWCD 5
|
 |
Larry Homes
Greenhorn
Joined: Jan 18, 2009
Posts: 25
|
|
|
I am using eclipse to do all this. My usual method is to export the project as a .war file into the tomcat webapp directory. I tried moving the resource folder out of the WEB-INF folder, but it is then no longer packaged in the .war file. The only folders in /webapps/test/ are META-INF and WEB-INF
|
 |
Gopikrishna Kunisetty
Ranch Hand
Joined: Jun 12, 2008
Posts: 35
|
|
After moving the images location, are you able to load images into your page.
I'm able to export images to .war file..
|
 |
Larry Homes
Greenhorn
Joined: Jan 18, 2009
Posts: 25
|
|
Ok i made a mistake. I have now made resource a sibling of WEB-INF and it is exported with the war. The path to the img is now
/webapps/test/resources/img.png
Here is the img in the page
but it still doesn't load the image.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Your URL looks suspect. If the context path for the web app is /test, that's the first thing that should be in the URL.
You should learn how to create and deploy web apps outside of an IDE,. It's clear that the IDE crutch is preventing you from knowing how things actually work.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
 |
|
|
subject: Referencing images in a servlet
|
|
|