tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reynir Hübner <rey...@hugsmidjan.is>
Subject RE: Getting the name of the context
Date Sat, 05 Oct 2002 09:12:01 GMT
You could try 

 ServletContext sc =  getServletContext();

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/servletapi/javax/servlet/GenericServlet.html#getServletContext()


And then:
String contextname = sc.getServletContextName();

Hope it helps
-reynir


> -----Original Message-----
> From: shanmugampl [mailto:shanmugampl@india.adventnet.com] 
> Sent: 5. október 2002 03:52
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Getting the name of the context
> 
> 
> 
> Thanks for your suggestion, but i load the servlet on startup 
> by giving 
> it in the <load-on-startup>. In the servlets init method i will be 
> initializing some basic parameters. Here I want the name of 
> the context 
> for regestering it. I do not have access to the request 
> object from my 
> init method. How do i get the name in this case.
> 
> 
> Craig R. McClanahan wrote:
> 
> >Use request.getContextPath().
> >
> >Craig
> >
> >On Fri, 4 Oct 2002, shanmugampl wrote:
> >
> >  
> >
> >>Date: Fri, 04 Oct 2002 17:20:52 +0530
> >>From: shanmugampl <shanmugampl@india.adventnet.com>
> >>Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>,
> >>     shanmugampl@india.adventnet.com
> >>To: tomcat-user@jakarta.apache.org
> >>Subject: Getting the name of the context
> >>
> >>  Hi,
> >>
> >>I have a requirement where i need to know the name of the 
> context i am 
> >>in.Say i have a servlet class present in my 
> >><Tomcat_Home>/webapp/myapp/. Now i want to get the name of the 
> >>application(in this case 'myapp') from my servlet. Is there 
> a way of 
> >>doing it. One of the way i found was specifying a name for the 
> >><display-name> attribute present in the web.xml. This name can be 
> >>retrieved from the ServletContext. The problem here is two contexts 
> >>can have the same display name which is not desired.
> >>
> >>Thanks
> >>Shanmugam.PL
> >>
> >>    
> >>
> >
> >  
> >
> 
> 

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