• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the proper relative URL for an image file that is under the WEB-INF tree?

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I clearly don't grok something fundamental about how an HTML or JSP page is supposed to refer to normal files when running under a serlet engine (tomcat or glassfish).

I normally put all my image files (.png, .jpg, .gif, etc.) in a directory that is a subdirectory to the "web" directory in my project. Thus these are in a parallel structure to the "WEB-INF" directory structure. I can easily load them into a bit of HTML or JSP with:



(where /webapi is my pageContext.request.contextPath)

But now, for reasons way too long to go into, I want to have a separate set of images (and CSS style and other stuff) in directories placed under the WEB-INF tree, not in parallel to it.

So I have a file whose path looks like:

and I'd expect to be able to have the images loaded with



But this doesn't work, its gets a 404.

I've tried every combination of moving the files up and down in the directory tree, and changing the reference URL, with no joy. And with no real idea if I'm getting close or not.

Can someone please:

1) tell me what the correct URL should be
2) tell me how to figure out what the general rules are so I can understand what is working
3) maybe point me to where this is documented?

Thanks
Pat
 
Maneesh Godbole
Saloon Keeper
Posts: 11343
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it should be /foo/images/baz.gif (or foo/images/baz.gif)
If I understand correctly, WEB-INF would be your "root" and everything would be relative to it.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:If I understand correctly, WEB-INF would be your "root" and everything would be relative to it.


No, not quite. The "web" directory is really the root, and that is where the index.jsp goes, this being the file that is delivered when
the user enters a URL of "pfarrell.com/webapi

But under the "web" directory is "web/WEB-INF" and all the rest of the files of interest, including web.xml, sun-web.xml, and the default "classes" directory that is the place where you put things like log4j.properties, commons-logging.properties and other resources that are not in the usual com.pfarrell.foo
structure of Java classes.

If everything was rooted in WEB-INF and relative to it, I'd be happy and done. But its not. I have no idea what is controlling this.
 
Maneesh Godbole
Saloon Keeper
Posts: 11343
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ok. Understood now.
What about WEB-INF/foo/images/baz.gif or /WEB-INF/foo/images/baz.gif Does that work?
 
Tim Moores
Bartender
Posts: 3137
50
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing that is in WEB-INF will ever get served directly to a client.
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Nothing that is in WEB-INF will ever get served directly to a client.


Ah, that is a critical piece of information, that I was missing.

Thanks
Pat
 
Tim Moores
Bartender
Posts: 3137
50
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's actually in the servlet spec. JSPs are generally kept somewhere in WEB-INF, so that they are not accessible directly, but only via a servlet that forwards to them or includes them.
 
Piyush Mangal
Ranch Hand
Posts: 196
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the resources under WEB-INF are secure and can not be publicly available. Ideally all the secured resources are put in WEB-INF folder. Only servlets and JSPs can access these resource under WEB-INF. As browser sends another request to load image as it encounters the same in an HTML page, that is why you are not able to see an image on screen.
 
varun Dosapati
Ranch Hand
Posts: 31
Java Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pat

This may be one solution, you can keep the images out of the WEB-INF ex. web/foo/images/xyz.jpg so that when the browser tries to access by /webapi/foo/images/xyz.jpg it will be available.

Hope this helps.

varun

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic