Richter, Stefanie (Student Assistant) wrote: > hello, > can anybody help me. > I want to use the include directive with JSP in Tomcat 4.0.3. Therefore I > want to use the relative path. > > For example if I use the relative path for: <img > src="/examples/images/code.gif"> it works, but if I want to include: > <%@ include file="/examples/jsp/include/foo.jsp" %> > I get the error file not found. > Does anybody hnow why and how I could solve this problem? > [...]
There are two types of paths you need to be aware of when using JSP: paths in HTML elements and paths in JSP elements. The main difference between them has to do with the "context path", i.e. the first part of a URI that is used to identify a specific web application. In the default Tomcat configuration, for instance, all examples are installed as a web application with the context path "/examples". A path in an HTML element (<src>, <form>, <a>, etc.) is interpreted by the browser. The browser knows nothing about context paths. You can use an absolute path, i.e. the full path from the server down to the file, including the context path: "/examples/images/code.gif", for a file located under the "images" directory in a web application with the context path "/examples". You can also use a path that's relative to the URL used to request it: "code.gif", for a file located in the same directory as the page that contains it, "../code.gif" for a file that is in the parent directory of the page that contains it, etc. A path in JSP element (<%@ include %>, <jsp:include>, <jsp:forward>) is interpreted by the JSP container, and it knows about the context path. You must therefore use a path that's either relative to the context path for the application, or relative to the page that contains it. A context-relative path starts with a slash and is interpreted as relative to the context path: "/jsp/include/foo.jsp" for a file located under the "jsp/include" directory in a web application with the context path "/examples". Page-relatiave paths are the same as for page-relative paths in HTML elements. I hope this helps, Hans -- Hans Bergsten [EMAIL PROTECTED] Gefion Software http://www.gefionsoftware.com JavaServer Pages 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://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com