aspose file tools*
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
Author

Read contextPath during initialization

Ben Souther
Sheriff

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30516
    
150

Ben,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ben Souther
Sheriff

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.

Example:


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