You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Mark R. Diggory" <md...@latte.harvard.edu> on 2002/08/26 22:17:47 UTC

Location of JSP page the Taglib is executing in

Hi,

I'm trying to write a Tag that knows the absolute file path of the JSP 
Page it is executing in (Not the request.getServletPath(), which could 
actually just be a servlet mapping) does anyone have any tips on how to 
get this in Tomcat? I was actually looking throught the actuall Catalina 
code base and came across a class org.apache.catalina.Globals which 
suggests that there are references to to things like (jsp-file, 
servlet-path) from the web.xml present in the request sttributes. But I 
fail to see them.

-Mark



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Again! Location of JSP page the Taglib is executing in (really Stuck on this one, PLEASE HELP).

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
I want my taglib to be able to resolve files relative to the jsp page 
its within. Unfortunately, the servlet-mapping seems to get in the way 
of this. I thought Tim's response was interesting so I tried it but I'm 
getting wierd responses (jndi: contexts) instead of filesystems. I'm 
thinking, is there a way to get at the resources relative to a JSP using 
the JNDI Context?

-Mark





Shawn Bayern wrote:

>Interestingly enough, I'm inclined to think the answer is "no."  Even if
>there's some creative way of doing it that eludes me, you're still not
>even guaranteed to *have* a filesystem at runtime.  So at best, a solution
>would be implementation-specific or container-specific.
>
>What do you need this information for?  There might be another way of
>doing it -- or, at worst, it might be enough to simply add some static,
>context-initialization parameters that supply the information you need.
>
>Shawn
>
>On Wed, 28 Aug 2002, Mark R. Diggory wrote:
>
>  
>
>>I really can't get to the bottom of this one.
>>
>>Is there any way to get to the "TRUE" filesystem location of the JSP 
>>page I am within? Even if the URI is Mapped through ServletMapping like 
>>below? I've tried getRealPath(...) and this is not accurate on the 
>>Tomcat 4.0.3 version I'm currently using.
>>
>>I need to get
>>
>>/var/tomcat4/webapps/Jaxp/JSPTransformExample.jsp (which really exists!)
>>
>>not
>>
>>/var/tomcat4/webapps/Jaxp/MapExample.jsp (which is virtual and doesn't 
>>exist!)
>>
>>    
>>
>>> <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>
>>>      
>>>
>>-Mark Diggory
>>
>>
>>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>>    
>>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>  
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Again! Location of JSP page the Taglib is executing in (really Stuck on this one, PLEASE HELP).

Posted by Shawn Bayern <ba...@essentially.net>.
Interestingly enough, I'm inclined to think the answer is "no."  Even if
there's some creative way of doing it that eludes me, you're still not
even guaranteed to *have* a filesystem at runtime.  So at best, a solution
would be implementation-specific or container-specific.

What do you need this information for?  There might be another way of
doing it -- or, at worst, it might be enough to simply add some static,
context-initialization parameters that supply the information you need.

Shawn

On Wed, 28 Aug 2002, Mark R. Diggory wrote:

> I really can't get to the bottom of this one.
> 
> Is there any way to get to the "TRUE" filesystem location of the JSP 
> page I am within? Even if the URI is Mapped through ServletMapping like 
> below? I've tried getRealPath(...) and this is not accurate on the 
> Tomcat 4.0.3 version I'm currently using.
> 
> I need to get
> 
> /var/tomcat4/webapps/Jaxp/JSPTransformExample.jsp (which really exists!)
> 
> not
> 
> /var/tomcat4/webapps/Jaxp/MapExample.jsp (which is virtual and doesn't 
> exist!)
> 
> >
> >  <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>
> 
> 
> -Mark Diggory
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Again! Location of JSP page the Taglib is executing in (really Stuck on this one, PLEASE HELP).

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Maybe this discussion would be more appropriate on the main 
Tomcat/Catalina list. I'll post it there instead.

Mark R. Diggory wrote:

> This gives me an interesting URL in return, I assume this is out of 
> Tomcats JNDI Context.
>
> <%java.net.URL theUrl = 
> pageContext.getServletContext().getResource("/");%>
> <%=theUrl.toString()%><BR>
>
> returns
>
> jndi:/localhost/Taglib/
>
> Not quite there, Is there a way to get
>
> Tim Kettering wrote:
>
>> Um, this code snippet is in one of my servlets, not a JSP page, but 
>> however,
>> since JSP pages do get compiled to servlets, this might be a clue to an
>> solution for you?
>>
>> There may be a more efficient way to do this, but this works 
>> perfectly fine
>> for me for determining where the root directory of the 
>> web-application is on
>> the physical server drive.
>>
>>    URL theUrl = sc.getResource("/");
>>    String webapp_base_dir = theUrl.getFile();
>>    return webapp_base_dir;
>>
>>
>>
>>  
>>
>>> I really can't get to the bottom of this one.
>>>
>>> Is there any way to get to the "TRUE" filesystem location of the JSP
>>> page I am within? Even if the URI is Mapped through ServletMapping like
>>> below? I've tried getRealPath(...) and this is not accurate on the
>>> Tomcat 4.0.3 version I'm currently using.
>>>
>>> I need to get
>>>
>>> /var/tomcat4/webapps/Jaxp/JSPTransformExample.jsp (which really 
>>> exists!)
>>>
>>> not
>>>
>>> /var/tomcat4/webapps/Jaxp/MapExample.jsp (which is virtual and doesn't
>>> exist!)
>>>
>>>   
>>>
>>>> <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>
>>>>     
>>>
>>> -Mark Diggory
>>>
>>>
>>>
>>> -- 
>>> To unsubscribe, e-mail:   
>>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail: 
>>> <ma...@jakarta.apache.org>
>>>
>>>   
>>
>>
>>  
>>
>
>
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Again! Location of JSP page the Taglib is executing in (really Stuck on this one, PLEASE HELP).

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
This gives me an interesting URL in return, I assume this is out of 
Tomcats JNDI Context.

<%java.net.URL theUrl = pageContext.getServletContext().getResource("/");%>
<%=theUrl.toString()%><BR>

returns

jndi:/localhost/Taglib/

Not quite there, Is there a way to get

Tim Kettering wrote:

>Um, this code snippet is in one of my servlets, not a JSP page, but however,
>since JSP pages do get compiled to servlets, this might be a clue to an
>solution for you?
>
>There may be a more efficient way to do this, but this works perfectly fine
>for me for determining where the root directory of the web-application is on
>the physical server drive.
>
>    URL theUrl = sc.getResource("/");
>    String webapp_base_dir = theUrl.getFile();
>    return webapp_base_dir;
>
>
>
>  
>
>>I really can't get to the bottom of this one.
>>
>>Is there any way to get to the "TRUE" filesystem location of the JSP
>>page I am within? Even if the URI is Mapped through ServletMapping like
>>below? I've tried getRealPath(...) and this is not accurate on the
>>Tomcat 4.0.3 version I'm currently using.
>>
>>I need to get
>>
>>/var/tomcat4/webapps/Jaxp/JSPTransformExample.jsp (which really exists!)
>>
>>not
>>
>>/var/tomcat4/webapps/Jaxp/MapExample.jsp (which is virtual and doesn't
>>exist!)
>>
>>    
>>
>>> <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>
>>>      
>>>
>>-Mark Diggory
>>
>>
>>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>>    
>>
>
>  
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Again! Location of JSP page the Taglib is executing in (really Stuck on this one, PLEASE HELP).

Posted by Tim Kettering <ti...@mac.com>.
Um, this code snippet is in one of my servlets, not a JSP page, but however,
since JSP pages do get compiled to servlets, this might be a clue to an
solution for you?

There may be a more efficient way to do this, but this works perfectly fine
for me for determining where the root directory of the web-application is on
the physical server drive.

    URL theUrl = sc.getResource("/");
    String webapp_base_dir = theUrl.getFile();
    return webapp_base_dir;



> I really can't get to the bottom of this one.
> 
> Is there any way to get to the "TRUE" filesystem location of the JSP
> page I am within? Even if the URI is Mapped through ServletMapping like
> below? I've tried getRealPath(...) and this is not accurate on the
> Tomcat 4.0.3 version I'm currently using.
> 
> I need to get
> 
> /var/tomcat4/webapps/Jaxp/JSPTransformExample.jsp (which really exists!)
> 
> not
> 
> /var/tomcat4/webapps/Jaxp/MapExample.jsp (which is virtual and doesn't
> exist!)
> 
>> 
>>  <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>
> 
> 
> -Mark Diggory
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

-- 
Tim Kettering
timster@mac.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Again! Location of JSP page the Taglib is executing in (really Stuck on this one, PLEASE HELP).

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
I really can't get to the bottom of this one.

Is there any way to get to the "TRUE" filesystem location of the JSP 
page I am within? Even if the URI is Mapped through ServletMapping like 
below? I've tried getRealPath(...) and this is not accurate on the 
Tomcat 4.0.3 version I'm currently using.

I need to get

/var/tomcat4/webapps/Jaxp/JSPTransformExample.jsp (which really exists!)

not

/var/tomcat4/webapps/Jaxp/MapExample.jsp (which is virtual and doesn't 
exist!)

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


-Mark Diggory



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Location of JSP page the Taglib is executing in

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Problems:

I'm trying to get the real file path to a "possibly" remapped jsp page

I.E. in web.xml -->

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

maps the request "/Jaxp/MapExample.jsp" to "/Jaxp/JSPTransformExample.jsp"

if I run your example on the following uri

http://localhost:8180/Jaxp/MapExample.jsp

I see

/var/tomcat4/webapps/Taglib/Taglib/Jaxp/MapExample.jsp

which is not what I'm looking for, I want to get back

/var/tomcat4/webapps/Taglib/Jaxp/JSPTransformExample.jsp

(This is because "application.getRealPath(...)" does nothing glorious 
but append the the string you feed it onto the real path to the Context. 
It may not neccessarily be a "Real" path.

-Mark

Ryan Lubke wrote:

>Let me try that again....
>
>I think you could use the requestURI() method of the
>HttpServletRequest object and pass that to
>ServletContext.getRealPath().
> 
>Example:
>
><% out.println(application.getRealPath(request.getRequestURI())); %>
>
>Output for the following request to the above code: 
>
>Request: http://localhost:8080/tomcat-docs/test.jsp
>
>Result:
>/files/projects/jakarta-tomcat-4.0/build/webapps/tomcat-docs/tomcat-docs/test.jsp
>
>You have to be careful when using this method. If the deployed application 
>is run out of the WAR file (it's not expanded on the filesystem), 
>then getRealPath will return null.
>
>  
>
>>On Mon, 2002-08-26 at 16:17, Mark R. Diggory wrote:
>>    
>>
>>>Hi,
>>>
>>>I'm trying to write a Tag that knows the absolute file path of the JSP 
>>>Page it is executing in (Not the request.getServletPath(), which could 
>>>actually just be a servlet mapping) does anyone have any tips on how to 
>>>get this in Tomcat? I was actually looking throught the actuall Catalina 
>>>code base and came across a class org.apache.catalina.Globals which 
>>>suggests that there are references to to things like (jsp-file, 
>>>servlet-path) from the web.xml present in the request sttributes. But I 
>>>fail to see them.
>>>
>>>-Mark
>>>
>>>
>>>
>>>--
>>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>>
>>>      
>>>
>>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>
>>    
>>
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>  
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Location of JSP page the Taglib is executing in

Posted by Ryan Lubke <Ry...@Sun.COM>.
Let me try that again....

I think you could use the requestURI() method of the
HttpServletRequest object and pass that to
ServletContext.getRealPath().
 
Example:

<% out.println(application.getRealPath(request.getRequestURI())); %>

Output for the following request to the above code: 

Request: http://localhost:8080/tomcat-docs/test.jsp

Result:
/files/projects/jakarta-tomcat-4.0/build/webapps/tomcat-docs/tomcat-docs/test.jsp

You have to be careful when using this method. If the deployed application 
is run out of the WAR file (it's not expanded on the filesystem), 
then getRealPath will return null.

> 
> 
> On Mon, 2002-08-26 at 16:17, Mark R. Diggory wrote:
> > Hi,
> > 
> > I'm trying to write a Tag that knows the absolute file path of the JSP 
> > Page it is executing in (Not the request.getServletPath(), which could 
> > actually just be a servlet mapping) does anyone have any tips on how to 
> > get this in Tomcat? I was actually looking throught the actuall Catalina 
> > code base and came across a class org.apache.catalina.Globals which 
> > suggests that there are references to to things like (jsp-file, 
> > servlet-path) from the web.xml present in the request sttributes. But I 
> > fail to see them.
> > 
> > -Mark
> > 
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Location of JSP page the Taglib is executing in

Posted by Ryan Lubke <Ry...@Sun.COM>.
I think you could use the requestURI and pass that to
ServletContext.getRealPath().

Example the folowing:

<% out.println(application.getRealPath(request.getRequestURI())); %>

Yields:

/files/projects/jakarta-tomcat-4.0/build/webapps/tomcat-docs/tomcat-docs/test.jsp

Have to be careful as if the deploy application is run out of the WAR
file (it's not expanded on the filesystem), then getRealPath will return
null.






On Mon, 2002-08-26 at 16:17, Mark R. Diggory wrote:
> Hi,
> 
> I'm trying to write a Tag that knows the absolute file path of the JSP 
> Page it is executing in (Not the request.getServletPath(), which could 
> actually just be a servlet mapping) does anyone have any tips on how to 
> get this in Tomcat? I was actually looking throught the actuall Catalina 
> code base and came across a class org.apache.catalina.Globals which 
> suggests that there are references to to things like (jsp-file, 
> servlet-path) from the web.xml present in the request sttributes. But I 
> fail to see them.
> 
> -Mark
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>