"Duffey, Kevin" wrote: > > Hi, > > This has been asked before, but I have yet to see a reply that answers what > I am after. In my case, we have two (or more) web-apps deployed (as Servlet > 2.2 web-apps, either expanded or using .war files). In each web-app, I have > various JSP pages that have href links, form actions, and img src links. My > question is, can I use the following: > > <img src="/images/image.gif"> > > or > > <a href="/path/page.jsp"></a> > > I recall seeing a problem with this when I deployed two web apps in the same > container. For some reason, I had to do ./path/page.jsp in order to get to > the page in the existing web-app. The main problem seems to lie in the > "root" web application and those that are accessed via a path. For example, > the root web application, which is our MAIN site, is ofcourse, the / root. > Therefore www.mycompany.com goes to this web application. It has /images > folder, /WEB-INF/classes, etc. Then, I have another web-app that starts from > the /admin path. So, in the admin web-app, if images use the <img > src="/images/path/image.gif"> format, is it infact looking for that image > from the ROOT web-app because of the / at the start? > > I guess the question is, when you might possibly be deploying any given > web-app into a container with other web-apps, is there a specific way to get > to paths via the web-app the path is being used in, and NOT access some > other web-apps? > > Worse case...you have web-app A deployed as root (/), then web-app B which > is at /B. They both have folders called /images in them. If web-app B uses > the "/images/" it is infact accessing the web-app A images folder... is this > right? So I would want all links/images/actions to be relative to the > web-app its deployed on. Can someone explain how to guarantee that? To allow the application to be deployed using any context path, you must either use relative paths for things like images and HTML links (e.g. "../images/image.gif") or add the context path to the elements dynamically: <img src="<%= request.getContextPath() %>/images/image.gif"> The reason is that the HTML elements are sent as-is to the browser (it's "template text" using JSP terminology) and it's the browser that interprets the references. The browser interprets an absolute path like /images/image.gif as an absolute path for the server that sent the page, so it will try to get exactly /images/image.gif from the same server, i.e. without adding the context path. I have a whole section describing all the intricate details about how URI references in HTML and JSP elements are interpreted in my JSP book in case you need more info: <http://TheJSPBook.com/> Hans -- Hans Bergsten [EMAIL PROTECTED] Gefion Software http://www.gefionsoftware.com Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.html http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
