package navigator;
import java.io.File;
import java.net.URL;
public class Navigator {
public URL location()
{
return navigator.Navigator.class.getClassLoader().getResource("navigator" + File.separator + "Navigator.class");
}
}
At 11:26 AM 12/11/2002 -0600, you wrote:
MicaelHello 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]>
-------------------------------------------------------
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 you
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
