Bernd WENDER wrote:

> Dear JSP Community,
>
> I have the following problem under the SUN reference implementation
> jswdk-1.0:
> I tried to forward a request from a servlet to a JSP page using
>
> rd.forward(request, response),
>
> where rd is the request dispatcher:
>
> RequestDispatcher rd =
> sc.getRequestDispatcher("/htmlgeos/AdminClient.jsp");
>
> sc is my servlet context:
>
> ServletContext sc = getServletContext();
>
> /htmlgeos is mapped to my application root directory using the
> configuration in 'webserver.xml':
>
> <WebServer id="webServer">
>     <Service id="service0">
>         <WebApplication id="htmlgeos" mapping="/htmlgeos"
> docBase="w:/work/htmlgeos-1"/>
>     </Service>
> </WebServer>
>
> Apparently the request dispatcher doesn't take care of the /htmlgeos
> mapping.
> It looks for AdminClient.jsp in the server's install path instead:
>
> real path of /htmlgeos/AdminClient.jsp:
> ;D:\jswdk-1.0\webpages\htmlgeos\AdminClient.jsp
> [which I found out using sc.getRealPath("/htmlgeos/AdminClient.jsp") ]
>
> Putting AdminClient.jsp in the above mentioned directory works fine. But of
>  course this is not what I want.
>
> (Invoking /htmlgeos/AdminClient.jsp by typing in its URL in a browser
> window works, too. It also works if
> I use it as a target of a POST operation in an HTML form.)
>
> Question: is this a bug or am I doing something wrong?
>
> Bernd
>

Request dispatchers (and most of the other places in the servlet API that talk
about URLs) want to have paths that are relative to the "context path" for your
servlet context.  Because you have mapped the context to "/htmlgeos", the
following statement should work instead:

RequestDispatcher rd =
    sc.getRequestDispatcher("/AdminClient.jsp");

The reasoning behind this requirement is that now you are free to change the
mapping in the webserver.xml file to some other prefix, without having to change
anything in your code.

The same rule applies to page URIs in things like <jsp:forward> and <jsp:include>.

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to