Nadler Paul wrote:
>
> Folks -
>
> I have a site in which JSPs call other JSPs, which often call other JSPs, etc.,
> all using <jsp:include...>. In this setting, how can any given JSP determine its
> own path and name, and the path and name of the JSP that called it?
>
> I have tried request.getServletPath() and request.getHeader('REFERER'), but they
> only return the top-level calling JSPs.
>
> Hint: Using the 'this' keyword, as in this.toString(), returns the full name of
> the current compiled class. This is a start, but is there a method I can apply
> to 'this' that will give me just the path and name of the JSP?
When you include a servlet or JSP page, using <jsp:include>, the container
sets a number of request attributes with information about the URI for the
included JSP (or servlet):
javax.servlet.include.request_uri
javax.servlet.include.context_path
javax.servlet.include.servlet_path
javax.servlet.include.path_info
javax.servlet.include.query_string
If you want the absolute path to the included JSP, suitable for use as an
HTML reference or in a sendRedirect() call, use:
String absURI = request.getAttribute("javax.servlet.include.request_uri");
If you need the context relative path, use:
String ctrURI = request.getAttribute("javax.servlet.include.servlet_path");
All of this is described in more detail in the Servlet 2.2 specification,
in the Dispatching Requests section.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
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