You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Zsolt Koppany <zk...@intland.com> on 2007/10/13 13:38:40 UTC
How to get the context path during servlet load?
Hi,
I want to make the application contextPath independent. Normally this is not
a problem because I can use request.getContextPath() however I need to know
the contextPath during startup:
<servlet>
<servlet-name>startup</servlet-name>
<servlet-class>...</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</servlet>
How can I do that?
Zsolt
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get the context path during servlet load?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Pid,
Pid wrote:
> ServletContext context = config.getServletContext();
> String path = context.getContextPath();
I can't remember if this is the same thread (the original message has
fallen off my list queue), but I thought the OP was using Servlet API
2.4, which does not have this method. :(
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHENu/9CaO5/Lv0PARAsEOAJ4tqESIpIHpwJKZCj2hcp1ekmA8ygCguvbB
twrBApqjtx55+x9G33xi+0M=
=041X
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to get the context path during servlet load?
Posted by Pid <p...@pidster.com>.
if you mean during the init() method:
/*
* (non-Javadoc)
* @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
*/
@Override
public void init(ServletConfig config) throws ServletException {
//
ServletContext context = config.getServletContext();
String path = context.getContextPath();
super.init(config);
}
Zsolt Koppany wrote:
> Hi,
>
> I want to make the application contextPath independent. Normally this is not
> a problem because I can use request.getContextPath() however I need to know
> the contextPath during startup:
>
> <servlet>
> <servlet-name>startup</servlet-name>
> <servlet-class>...</servlet-class>
> <load-on-startup>1</load-on-startup>
> </servlet>
> </servlet>
>
> How can I do that?
>
> Zsolt
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org