Craig R. McClanahan wrote: >You seem to be making an unwarranted assumption, that there *is* such a >thing as a directory for a context. >
Not neccessarily unwarranted, It is apparent that there is a JNDI Context available for resources in Tomcat and that the Servlet API specifies that the Implementor is required to provide URLConnections (Jar/Http what have you) to the said resources, so that a file could reside in a War package or Database or what have you. Saying that "/" is required in the Servlet Spec. for getResource("/") is suggesting that there *is* a concept of a "path" even if the path is a "name" resolved in a JNDI Context/SubContext . I'm simply suggesting that it would be more powerfull to adopt some simple means to resolve resources relative to "Object" making the request as well as absolutely. >Such a thing is not required by the >servlet spec -- it's perfectly reasonable to run webapps directly from a >WAR file, or to represent the static contents in a database, or lots of >other interesting possibilities -- and in none of those cases is there a >directory to give you the path for. > For example: In the Java Object model. object.getClass().getResource("....") provides a Mechanism to resolve both resources relative to the Class/Package of the object and absolutely from the classpath root. Now, are Java packages neccessarily directory structures? No, they can reside in a Jar File or in the case of "Corba/RMI/Object servers what have you", just about any where. But when it comes down to it object.getClass().getResource("/foobar.txt") means absolutely and object.getClass().getResource("foobar.txt") means relatively. Do they not convey this nature even though they may not actually be file paths? As such I still like the idea of the following options at least! application.getResource("/") resolve to the subcontext of the Servlet Context Root application.getResource("") resolve to the subcontext of the Servlet/JSP This would seem logical and much more powerfull, would it not? >You should also note that allowing ".." to resolve "above" the webapp >would open up huge security holes for malicious webapps to negatively >affect the operation of other webapps on the same server. > application.getResource("..") resolve to the parent subcontext/directory of the Servlet/JSP Ok, I'll give up on this one as it *is* seemingly file path like in nature...I don't have a valid JNDI context like example of such an operation. > >The ServletContext.getResource() family of methods work the way they do in >order to ensure portable access to resources within the web application, >no matter how the servlet container chooses to implement the APl's. > >>-Mark Diggory >> >> > >Craig > > > > >> >> Shapira, Yoav wrote: >> >> >> >>>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:[EMAIL PROTECTED]] >>>>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:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>