• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Referencing images in a servlet

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic