Well, this is really a browser issue.  The browser tries to figure out what
the url is for the page that it is viewing, and it doesn't worry too much
about what happens on the server side to generate the page.  The same
problem actually exists for cgi programs, where normal HTML pages are stored
in a different path than the cgi programs.  I try to give the browser a
hand, and what works for me is the following:

Use the <base href="..."> HTML tag in the <head> section of your JSP.  Set
the href to a value that will allow all relative SRC and HREF attributes on
the JSP page to point to the correct place.  For greater flexibility, set an
init parameter or a property file entry for your servlet (e.g., call it
"htmlbase").  In the servlet init method, pop the value of the parameter
into the ServletContext, and use the JSP built in "application" object to
retrieve it.  So the <base> tag looks like: <base href="<%=
application.getAttribute("htmlbase") %>">.  This provides maximum
flexibility if you have to install your servlet in an environment that won't
allow you to set up aliases, etc.  The one possible drawback, is that you
must make sure your servlet is initialized before referring to any jsp that
have this tag.

Hope this helps.

----- Original Message -----
From: Neal Cabage <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, December 30, 2000 3:27 AM
Subject: funky-ass servlet forwarding


> 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);
>
>
> Thanks
>
> Neal
>
>
===========================================================================
> 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
>

===========================================================================
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