Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 2396 invoked from network); 12 Aug 2004 13:45:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 12 Aug 2004 13:45:51 -0000 Received: (qmail 24227 invoked by uid 500); 12 Aug 2004 13:45:15 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 24057 invoked by uid 500); 12 Aug 2004 13:45:14 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 23908 invoked by uid 99); 12 Aug 2004 13:45:12 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received: from [216.148.227.85] (HELO rwcrmhc12.comcast.net) (216.148.227.85) by apache.org (qpsmtpd/0.27.1) with ESMTP; Thu, 12 Aug 2004 06:45:09 -0700 Received: from nicki.visi.com (c-66-41-141-26.mn.client2.attbi.com[66.41.141.26]) by comcast.net (rwcrmhc12) with SMTP id <2004081213450601400r3mv2e>; Thu, 12 Aug 2004 13:45:06 +0000 Message-Id: <5.2.1.1.0.20040812084306.042c52e8@pop.shell.visi.com> X-Sender: hoju@pop.shell.visi.com X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Thu, 12 Aug 2004 08:45:01 -0500 To: "Tomcat Users List" From: Jacob Kjome Subject: Re: SOLVED: How to get the context path for a web application? In-Reply-To: References: <027801c47fbc$50f9bda0$3201a8c0@rasta> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N To get the context path at init time, try this.... from: http://cvs.apache.org/viewcvs.cgi/logging-log4j-sandbox/src/java/org/apache/log4j/servlet/InitShutdownController.java /** * Retrieves the context path of the web application from the servlet context. * * @param context the current servlet context * @return the derived context path, guaranteed non-null */ private static String getContextPath(final ServletContext context) { //old way to determine context path //String tempdir = "" + //context.getAttribute("javax.servlet.context.tempdir"); //int lastSlash = tempdir.lastIndexOf(File.separator); //if ((tempdir.length() - 1) > lastSlash) { // logHomePropName = tempdir.substring(lastSlash + 1) + ".log.home"; //} String contextPath = ""; try { //use a more standard way to obtain the context path name //which should work across all servers. The tmpdir technique //(above) depends upon the naming scheme that Tomcat uses. String path = context.getResource("/").getPath(); //first remove trailing slash, then take what's left over //which should be the context path less the preceeding //slash such as "MyContext" contextPath = path.substring(0, path.lastIndexOf("/")); contextPath = contextPath.substring(contextPath.lastIndexOf("/") + 1); } catch (Exception e) { ; } return contextPath; } Jake At 10:28 AM 8/12/2004 +0200, you wrote: >On Wed, 11 Aug 2004, David Wall wrote: > >| > The cause for some of these specs is the fact servlet containers aren't >| > required to run on file systems. For example, they may run entirely >| > inside a DBMS (and Oracle had such a container for a while), in which >| > case you must deploy in a packed WAR and the subset under a server's >| > URL name space is not a hard-drive path. > >I do know this. > >| >| Nobody "cares" if this maps to a file system or not. > >Totally agree - it has nothing at all with filesystem, or whether the >webapp is stored on a read-only stone-tablet - I want to know what "subset >of the webserver's URL namespace" I'm mounted beneath, at init time. What >I'll do with that information is my business! > As this is a static element; the webapp is, -per definition- (The >javadoc snippet) mounted beneath a "subset of the URL namespace"; there is >no reason I can fathom why this shouldn't be made available to "us coders" >that are making webapps, at init time. The point is that the webapp won't >change "mount point" from request to request, will it? So the web >container must know at init-time which sub-space it will mount the webapp >under.. Just please make that information available then, at init time! > >IMO, that is. > > ( -My- use-case is, as mentioned, that I want to make it easy for >developers to override some (development-)settings of the framework. In >the webapp I'll check whether it is possible to do file-system access and >System-property-getting, and if so, then check for and read the files >$userdir/devel/develconfig.xml, and then >$userdir/devel//develconfig.xml. It if it is not possible, >then I won't do that, and assume that I am in a production environment or >something. ) > >I'd just love to see this extra method added. > >Endre. > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org