tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: Is this a Bug in request.getServletPath() ?
Date Thu, 29 Aug 2002 13:58:26 GMT
I believe that if you access it via a mapping, that's how you will see
its location.  So if you go to the real location in the browser, i.e.
/Jaxp/JSPTransformExample.jsp, you will get that location instead of the
mapped one.

In general, you are not guaranteed to have access to the server's
mappings, much less the ability to introspect them as you would like in
this use case.

A better approach may be to use getResource() and/or
getResourceAsStream(), as that would give you the resource and would
work in a WAR, which the getRealPath() approach won't.

Yoav Shapira
Millennium ChemInformatics

>-----Original Message-----
>From: Mark R. Diggory []
>Sent: Thursday, August 29, 2002 9:53 AM
>To: Tomcat Users List
>Subject: Is this a Bug in request.getServletPath() ?
>I'm trying to get a file in the filesystem relative to the location of
>JSP Page. At first Blush the following would seem appropriate:
>String jsp_location =
>String relative =
>... get the resource using this path ...
>however, when one uses a servlet mapping on a JSP Page like below.
> <servlet>
>   <servlet-name>JSPTestMap</servlet-name>
>   <jsp-file>/Jaxp/JSPTransformExample.jsp</jsp-file>
> </servlet>
> <servlet-mapping>
>   <servlet-name>JSPTestMap</servlet-name>
>   <url-pattern>/Jaxp/MapExample.jsp</url-pattern>
> </servlet-mapping>
>request.getServletPath() returns
>and not
>is there any way I can get hold of the original real location of the
>Page I'm working in and have it also work with servlet-mappings?
>-Mark Diggory
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>For additional commands, e-mail: <mailto:tomcat-user-

View raw message