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.
http://barracuda.enhydra.org/software/cvs/cvsweb.cgi/Projects/EnhydraOrg/toolsTech/Barracuda/src/org/enhydra/barracuda/core/helper/servlet/ResourceGateway.java

Jake

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 for
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 of
BF> JSPs, e.g. you need a lot of ../ if you have nested a lot of directories.

BF> cu,
BF>         boris



-- 
Best regards,
 Jacob                            mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to