tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: Is this a Bug in request.getServletPath() ?
Date Thu, 29 Aug 2002 13:58:26 GMT
Hi,
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 [mailto:mdiggory@latte.harvard.edu]
>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
a
>JSP Page. At first Blush the following would seem appropriate:
>
><%
>String jsp_location =
application.getRealPath(request.getServletPath());
>
>String relative =
jsp_location.substring(0,jsp_location.lastIndexOf("/"));
>
>... 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
>
><url-pattern>/Jaxp/MapExample.jsp</url-pattern>
>
>and not
>
><jsp-file>/Jaxp/JSPTransformExample.jsp</jsp-file>
>
>is there any way I can get hold of the original real location of the
JSP
>Page I'm working in and have it also work with servlet-mappings?
>
>-Mark Diggory
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>unsubscribe@jakarta.apache.org>
>For additional commands, e-mail: <mailto:tomcat-user-
>help@jakarta.apache.org>


Mime
View raw message