Neal Cabage wrote:
>
> I am using a servlet to perform some logic, and it then forwards to a JSP.
> The problem is that the URL (in the display) still says the name URL  of
> the servlet not the JSP, and thus the relative paths of the links in the JSP
> are all messed up.  They're trying to link relative to the servlet, not the
> JSP.
> *AND* I can't seem to figure out a way to specify an absolute path using the
> following
> syntax ... it won't accept one.  ANy thoughts?
>
>         ...
>         String URL = "/qaTool/index.jsp";
>         ServletContext sc = getServletContext();
>         RequestDispatcher rd = sc.getRequestDispatcher(URL);
>         rd.forward(request,response);

I assume that you invoke the servlet with a URI like /servlet/myServlet?
If so, one way around the problem with relative paths in the JSP page
is to define a URI mapping for your servlet instead.

Your JSP page seem to be accessible through the URI /qaTool/index.jsp.
If it contains relative URIs, like "foo.jsp", "logo.gif", etc., the
browser will try to resolve them based on the current URI, in your
case /servlet/myServlet, and ends up with the wrong result as you
have seen. But you can define a URI mapping like this for the servlet
in the web.xml file:

  <servlet-mapping>
    <servlet-name>myServlet</servlet-name>
    <url-pattern>/qaTool/myServlet/*</url-pattern>
  </servlet-mapping>

You can then invoke the servlet as /qaTool/myServlet and the browser
will be able to resolve the relative URIs in the JSP page you forward
to since now the servlet and all the other resources are invoked with
URIs at the same level in the URI tree.

I discuss this in much more detail in my JavaServer Pages book:

  <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

Reply via email to