jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Read contextPath during initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Read contextPath during initialization" Watch "Read contextPath during initialization" New topic

Read contextPath during initialization

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Does anyone know of a spec compliant way of determining the contextPath during context initialization?

The only getContextPath method I can find is part of the ServletRequest.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

The only way I can think of is to pass the contextPath in a property file or the like. What are you trying to do with the path? Maybe there is another way.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The middleware we use to connect to our database uses an ini file to map apps to accounts in the database.


Right now, I'm configuring the account name 'myapp' in the deployment descriptor which means that every time the customer wants to upgrade, they have to unpack the app and edit the web.xml file.

If there was a dependable way to determine the contextPath at startup, it would be possible for them to just rename the war file and drop it in the webapps directory (we're using Tomcat).

I'm very surprised that ServletContext doesn't have a getContextPath method.

This works but it's so replusive that I can't look at it without getting sick.
[ February 28, 2005: Message edited by: Ben Souther ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Read contextPath during initialization
It's not a secret anymore!