• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Referencing images in a servlet

 
Larry Homes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Larry Homes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic