tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ron Day" <>
Subject RE: How to access /images?
Date Wed, 11 Dec 2002 19:51:06 GMT
nice solution...... is there a reason why you didn't make location a static
method ?


-----Original Message-----
From: micael []
Sent: Wednesday, December 11, 2002 1:23 PM
To: Tomcat Users List
Subject: Re: How to access /images?

Don't know if this helps, but I put a Navigator class in
WEB-INF/classes/navigator/ and by accessing its ClassLoader can always tell
what the paths on the server are.  The sole purpose of this class is to
reveal information not capable of being known prior to startup (e.g. is
this Unix, XP, or Memorex?) and providing this to any part of the whole
deal that needs to know.  The parts can then use the information as they
like.  I usually create another class which gives me the location of the
application itself, which is stored in application scope and everything
from there is up to the individual parts to specify where they are relative
to that.

package navigator;


public class Navigator {

     public URL location()

navigator.Navigator.class.getClassLoader().getResource("navigator" +
File.separator + "Navigator.class");



At 11:26 AM 12/11/2002 -0600, you wrote:
>Hello Boris,
>This issue is much more problematic in servlets.  Since you know which
>directory your .jsp file is relative to your images, I would continue
>using relative paths.  This is what you'd need to do for static html
>files anyway.  For servlets, prepending the context path is probably a
>good idea, but make sure to ask the servlet api what the current
>context path is instead of just assuming your app will always be
>called, for instance, "myapp".  The name could change or it could be
>served off the root context where the context path would be "/" so
>always grab that value dynamically.
>Otherwise, use an MVC pattern and access a servlet via a mapping to
>your controller at the root of the context and *only* at the root of
>the context.  That way, you always know where your static resources
>exist relative to the current dynamic page.
>Otherwise, you can always pre-pend all static resources with some path
>which maps to a servlet which serves resources out of a classloader.
>You could put your images in a .jar file in some package.  that way,
>no matter where your page is, you always know exactly how to refer to
>the resources since the package name never changes.  The Barracuda
>project has such a servlet called ResourceGateway which you can take a
>look at here.
>Wednesday, December 11, 2002, 11:03:18 AM, you wrote:
>BF> Hi!
>BF> What's the preferred way of accessing e.g. images or other JSPs using
>BF> absolute pathnames in a JSP? If I use something like
>BF> <img src="/images/pic.gif"> this does not work if the webapp is not
>BF> deployed to the root context. There are some methods in ServletContext
>BF> path handling, which should be used for constructing the right path?
>BF> I think it should look like that
>BF> <img src='<% magicthing("/images/pic.gif") %>'>
>BF> Does anybody know what the magicthing should be? At the moment I use
>BF> relative pathnames, but that gets complicated if you really have a lot
>BF> JSPs, e.g. you need a lot of ../ if you have nested a lot of
>BF> cu,
>BF>         boris
>Best regards,
>  Jacob                  
>To unsubscribe, e-mail:
>For additional commands, e-mail:



This electronic mail  transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged.  This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited.  If you
have received this transmission in error, please delete the message.  Thank

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message