tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject RE: get Servlet Context Name
Date Tue, 02 Oct 2001 04:38:05 GMT

On Mon, 1 Oct 2001, chiuming wrote:

> Date: Mon, 1 Oct 2001 20:45:19 -0700 (PDT)
> From: chiuming <>
> Reply-To:
> To:
> Subject: RE: get Servlet Context Name
> could you tell me more how to make a filter?
> are you meaning init-parameter in web.xml?

See Chapter 6 of the Servlet 2.3 Specification, available via:

There have also been numerous JavaWorld articles (as well as Java Tech
Tips on covering filters.  Use the search
engines on those sites to identify useful articles.

> inorder to call getRealPath("/"), I think I must have
> a request.

Nope .. the ServletContext.getRealPath() will work from an init() method
as well.  *However*, if your web app is running in a servlet container
that runs apss directly from a WAR file (like Tomcat can) or from some
other non-filesystem-based architecture (for example, the Oracle container
that served its static content from BLOB objects in the database), this
call will return null.

The portable way to access static resources within your web app is to use
the ServletContext.getResource() and ServletContext.getResourceAsStream()
methods.  See the servlet spec, and the associated JavaDocs, for more

> anyway I can get the path(context) name
> during servlet init() stage?

As I said before, there is no such thing as a context name in Servlet 2.2.
What is it that you are trying to accomplish?

If you want the context *path*, it is only available during a request.

> thanks again.


View raw message