You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Vijayanand Sukumar <VS...@manage.com> on 2000/12/01 08:04:36 UTC

How to get webapp context path from javax.servlet API in init me thod?

Can I get the context path in the init() method of the server because i do
not have a request object there???

Thanks 
Vijay

-----Original Message-----
From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
Sent: Thursday, November 30, 2000 10:22 AM
To: tomcat-user@jakarta.apache.org
Subject: Re: How to get webapp context path from javax.servlet API?


Vijayanand Sukumar wrote:

> Hi ,
> I need to know if there is a way to get the context path from without
> creating  a dependency on tomcat. If my web-app context is /foo and I want
> to convert a  URL relative to the current context back into an external
URL
> with the full  syntax.

When processing a servlet request, simply call

    String contextPath = request.getContextPath();

and you can use this value to construct an absolute URL.

>
> Thanks
> Vijayanand Sukumar

Craig McClanahan


Re: How to get webapp context path from javax.servlet API in init method?

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Vijayanand Sukumar wrote:

> Can I get the context path in the init() method of the server because i do
> not have a request object there???
>

No ... it is only accessible when a request is being processed.

>
> Thanks
> Vijay
>

Craig