Re: SOLVED: How to get the context path for a web application?
> Someone on the list suggested Request.getContextPath() and it works like a > charm. Thanks to all. Agreed, but my follow-up question was if there was such a call to be done using a ServletContext/ServletConfig object so that you can get the context path in initialization servlets, etc., before a request comes in. David > >> A ServletConfig reference is passed in the call to the init() method of > > your > >> servlet. From this you may use the getServletContext() method to get the > >> context. One thing to remember is that this does not get called until the > >> servlet is initialized and would be invalidated when it is destroyed. I > > suggest > >> you check the API docs for more information. > > > > But do any of those return the context path? I didn't see it anywhere in > > the javadocs. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
Hi, >Agreed, but my follow-up question was if there was such a call to be done >using a ServletContext/ServletConfig object so that you can get the context >path in initialization servlets, etc., before a request comes in. No, and an archive search would reveal past discussions around this issue (though none recently). Webapps are supposed to be independent of their server configuration including with regards to context path, and so the Servlet Spec actively discourages you from doing webapp initialization or configuration based on such data. A lot of people debated for a long time what does and doesn't go into the ServletContext/ServletConfig objects as opposed to Request/Response objects. Yoav This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
> No, and an archive search would reveal past discussions around this > issue (though none recently). Webapps are supposed to be independent > of their server configuration including with regards to context path, > and so the Servlet Spec actively discourages you from doing webapp > initialization or configuration based on such data. A lot of people > debated for a long time what does and doesn't go into the > ServletContext/ServletConfig objects as opposed to Request/Response > objects. True and it's mostly not a big issue. However, is it possible for a ServletContext to reference one context path and the Request objects to have a different one? Most webapps only operate under a single context path (don't they?), so having it at initialization would be nice too. Oh well... With the path, I could build URLs for email and other logging info at initialization that cannot be done dynamically without knowing the host/port/contextpath. David - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
On Tue, 10 Aug 2004, David Wall wrote: > > No, and an archive search would reveal past discussions around this > > issue (though none recently). Webapps are supposed to be independent > > of their server configuration including with regards to context path, > > and so the Servlet Spec actively discourages you from doing webapp > > initialization or configuration based on such data. A lot of people > > debated for a long time what does and doesn't go into the > > ServletContext/ServletConfig objects as opposed to Request/Response > > objects. > > True and it's mostly not a big issue. However, is it possible for a > ServletContext to reference one context path and the Request objects to have > a different one? Most webapps only operate under a single context path > (don't they?), so having it at initialization would be nice too. Oh well... > With the path, I could build URLs for email and other logging info at > initialization that cannot be done dynamically without knowing the > host/port/contextpath. You could always pass it in yourself as a context variable (i.e., context init-param). The problems then are that you're duplicating data and reducing portability. Milt Epstein Research Programmer Integration and Software Engineering (ISE) Campus Information Technologies and Educational Services (CITES) University of Illinois at Urbana-Champaign (UIUC) [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
If you set your container to start a pool of servlets when it starts, the init should be called then. I'm not sure how to set Tomcat to start up a pool of "Keep alive" servlets. You'll have to consult the docs for that. The init is called when the servlet is instantiated and should be called before requests are made if the servlet is started before request arrive. I have done this with other servlet containers. Robert S. Harper 801.265.8800 ex. 255 > -Original Message- > From: David Wall [mailto:[EMAIL PROTECTED] > Sent: Tuesday, August 10, 2004 11:27 AM > To: Tomcat Users List > Subject: Re: SOLVED: How to get the context path for a web application? > > > Someone on the list suggested Request.getContextPath() and it works like a > > charm. Thanks to all. > > Agreed, but my follow-up question was if there was such a call to be done > using a ServletContext/ServletConfig object so that you can get the context > path in initialization servlets, etc., before a request comes in. > > David > > > > >> A ServletConfig reference is passed in the call to the init() method of > > > your > > >> servlet. From this you may use the getServletContext() method to get > the > > >> context. One thing to remember is that this does not get called until > the > > >> servlet is initialized and would be invalidated when it is destroyed. I > > > suggest > > >> you check the API docs for more information. > > > > > > But do any of those return the context path? I didn't see it anywhere > in > > > the javadocs. > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
Hi, >True and it's mostly not a big issue. However, is it possible for a >ServletContext to reference one context path and the Request objects to >have >a different one? Most webapps only operate under a single context path >(don't they?), so having it at initialization would be nice too. Oh >well... >With the path, I could build URLs for email and other logging info at >initialization that cannot be done dynamically without knowing the >host/port/contextpath. All webapps operate under one context path: that's a one to one relationship at the core of the Servlet Specification. Note that one reason the ServletContext object does have a context path is that the latter is an HTTP-specific concept. (One has to be very careful here as these terms are used interchangeably). The ServletContext and ServletConfig objects are explicitly protocol-independent. Specifically, what the ServletContext JavaDoc calls "uripath" may or may not correspond to a path on the hard-drive and in the Request#getContextPath method. There's more to this but I have to run to a meeting ;) Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
that's me! =) it's nice to be of service... welcome! aris -Original Message- From: Dov Rosenberg [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 11, 2004 1:23 AM To: Tomcat Users List Subject: SOLVED: How to get the context path for a web application? Someone on the list suggested Request.getContextPath() and it works like a charm. Thanks to all. On 8/10/04 1:06 PM, "David Wall" <[EMAIL PROTECTED]> wrote: >> A ServletConfig reference is passed in the call to the init() method >> of > your >> servlet. From this you may use the getServletContext() method to get >> the context. One thing to remember is that this does not get called >> until the servlet is initialized and would be invalidated when it is >> destroyed. I > suggest >> you check the API docs for more information. > > But do any of those return the context path? I didn't see it anywhere > in the javadocs. > > David > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- Dov Rosenberg Conviveon Corporation http://www.conviveon.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
Thanks again On 8/10/04 7:52 PM, "Aris Javier" <[EMAIL PROTECTED]> wrote: > that's me! =) > it's nice to be of service... > > welcome! > > aris > > -Original Message- > From: Dov Rosenberg [mailto:[EMAIL PROTECTED] > Sent: Wednesday, August 11, 2004 1:23 AM > To: Tomcat Users List > Subject: SOLVED: How to get the context path for a web application? > > > Someone on the list suggested Request.getContextPath() and it works like > a charm. Thanks to all. > > > > On 8/10/04 1:06 PM, "David Wall" <[EMAIL PROTECTED]> wrote: > >>> A ServletConfig reference is passed in the call to the init() method >>> of >> your >>> servlet. From this you may use the getServletContext() method to get >>> the context. One thing to remember is that this does not get called >>> until the servlet is initialized and would be invalidated when it is >>> destroyed. I >> suggest >>> you check the API docs for more information. >> >> But do any of those return the context path? I didn't see it anywhere > >> in the javadocs. >> >> David >> >> >> - >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> -- Dov Rosenberg Conviveon Corporation 370 Centerpointe Circle, suite 1178 Altamonte Springs, FL 32701 http://www.conviveon.com [EMAIL PROTECTED] AOL IM: dovrosenberg (407) 339-1177 x102 (407) 339-6704 (fax) (800) 475-9890 (407) 310-8316 (cell) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
On Tue, 10 Aug 2004, Shapira, Yoav wrote: | | Hi, | | >Agreed, but my follow-up question was if there was such a call to be | done | >using a ServletContext/ServletConfig object so that you can get the | context | >path in initialization servlets, etc., before a request comes in. | | No, and an archive search would reveal past discussions around this | issue (though none recently). Webapps are supposed to be independent | of their server configuration including with regards to context path, | and so the Servlet Spec actively discourages you from doing webapp | initialization or configuration based on such data. A lot of people | debated for a long time what does and doesn't go into the | ServletContext/ServletConfig objects as opposed to Request/Response | objects. I'm jumping in on this thread, since I just had the same problem: I wanted to do some initing for developers on a particular setup, where I wanted to be able to override init (development-)settings per user per webapp w/o messing with any webapp-specific config files. Per user is OK, but per webapp is impossible. Look at this snippet from servlet JavaDocs..: [ http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html ] " There is one context per "web application" per Java Virtual Machine. (A "web application" is a collection of servlets and content installed under a specific subset of the server's URL namespace such as /catalog and possibly installed via a .war file.) " Thus, there is a -clear- notion of a Webapp living under "a specific subset of the server's URL namespace". What is that subset, please? I find it very non-coherent and non-consistent that you can get this on a request, but not on startup. Now, why is that? The argument about "supposed to be independent" doesn't do it for me: This independence isn't more enforced by -taking away- the information that you nonetheless have to, and are, given on a request. And it encourages, as you state in a later mail, folks to duplicate information in config files, e.g. web.xml - and at that point you most definately have ripped the independence of the webapp to small pieces. If anyone here will be on the next Servlet EG, then please ask these questions again! I'm informed that this has had its fair share of discussion before - but please either remove that JavaDoc, or -gimme the information- via the ServletContext object! Endre. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
Hi, Several Tomcat committers are in touch (and for that matter, personally know) several members of the Servlet Expert Group. 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. But then again, I'm not going to bother discussing this again, it's been done enough in the past. If you want to change the Spec, contact the expert group yourself, and I'm sure they'll weigh your concerns seriously. Yoav Shapira Millennium Research Informatics >-Original Message- >From: Endre Stølsvik [mailto:[EMAIL PROTECTED] >Sent: Wednesday, August 11, 2004 5:25 AM >To: Tomcat Users List >Cc: David Wall >Subject: RE: SOLVED: How to get the context path for a web application? > >On Tue, 10 Aug 2004, Shapira, Yoav wrote: > >| >| Hi, >| >| >Agreed, but my follow-up question was if there was such a call to be >| done >| >using a ServletContext/ServletConfig object so that you can get the >| context >| >path in initialization servlets, etc., before a request comes in. >| >| No, and an archive search would reveal past discussions around this >| issue (though none recently). Webapps are supposed to be independent >| of their server configuration including with regards to context path, >| and so the Servlet Spec actively discourages you from doing webapp >| initialization or configuration based on such data. A lot of people >| debated for a long time what does and doesn't go into the >| ServletContext/ServletConfig objects as opposed to Request/Response >| objects. > >I'm jumping in on this thread, since I just had the same problem: I wanted >to do some initing for developers on a particular setup, where I wanted to >be able to override init (development-)settings per user per webapp w/o >messing with any webapp-specific config files. Per user is OK, but per >webapp is impossible. > >Look at this snippet from servlet JavaDocs..: > >[ >http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext. >html ] > > " There is one context per "web application" per Java Virtual Machine. >(A "web application" is a collection of servlets and content installed >under a specific subset of the server's URL namespace such as /catalog and >possibly installed via a .war file.) " > >Thus, there is a -clear- notion of a Webapp living under "a specific >subset of the server's URL namespace". What is that subset, please? > >I find it very non-coherent and non-consistent that you can get this on a >request, but not on startup. Now, why is that? The argument about >"supposed to be independent" doesn't do it for me: This independence isn't >more enforced by -taking away- the information that you nonetheless have >to, and are, given on a request. And it encourages, as you state in a >later mail, folks to duplicate information in config files, e.g. web.xml - >and at that point you most definately have ripped the independence of the >webapp to small pieces. > > >If anyone here will be on the next Servlet EG, then please ask these >questions again! I'm informed that this has had its fair share of >discussion before - but please either remove that JavaDoc, or -gimme the >information- via the ServletContext object! > >Endre. > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
> 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. Nobody "cares" if this maps to a file system or not. If your application needs to create an URL that will take someone to a page on your site (let's say it's the /login.jsp page), we need to be able to set the protocol, domain, port and context path that will appear in front. For example, we have lots of emails that go out with such links back to the webapp, and today, we end up putting the complete URL in config files since there's no easy way to set these up in an "init" type method. That's just too bad since the context path doesn't change from request to request. David - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
hai use request.getContextPath() Rajesh Jacob Kjome wrote: 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
OHH!!. How could we be so stupid??? RTFT! (that last 'T' would be 'thread') > -Original Message- > From: Rajesh [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 12, 2004 8:47 AM > To: Tomcat Users List > Subject: Re: SOLVED: How to get the context path for a web > application? > > > hai > > > use > > request.getContextPath() > > Rajesh > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
On Thu, 12 Aug 2004, Jacob Kjome wrote: | To get the context path at init time, try this Thanks..! Good to see that others (log4j!!) have this problem! However, I have been thinking along these lines (the second idea presented) already, but it then again boils down to that you really cannot assume anything about what environment you're within. See, typically in the development environements we use, the dirname of the webapp have nothing in common with the "mount name" (you specify that in the tomcat server config file, or these other "xml-snippets" outside of the file) - thus I'm back to the starting point: no knowledge! If only the SerlvetContext object would be so nice as to have a simple method getContextPath(), we'd all be happy! Endre - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
Hi, No, not all of us will be happy. And it's not simple. Yoav Shapira Millennium Research Informatics >-Original Message- >From: Endre Stølsvik [mailto:[EMAIL PROTECTED] >Sent: Friday, August 13, 2004 5:27 AM >To: Tomcat Users List >Subject: Re: SOLVED: How to get the context path for a web application? > >On Thu, 12 Aug 2004, Jacob Kjome wrote: > >| To get the context path at init time, try this > >Thanks..! Good to see that others (log4j!!) have this problem! > However, I have been thinking along these lines (the second idea >presented) already, but it then again boils down to that you really cannot >assume anything about what environment you're within. See, typically in >the development environements we use, the dirname of the webapp have >nothing in common with the "mount name" (you specify that in the tomcat >server config file, or these other "xml-snippets" outside of the file) - >thus I'm back to the starting point: no knowledge! > >If only the SerlvetContext object would be so nice as to have a simple >method getContextPath(), we'd all be happy! > >Endre > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
Hi, And of course, since you can get the source for JSR154, there's nothing preventing you from adding this method and running with a custom servlet jar in your container. (It's at http://cvs.apache.org/viewcvs.cgi/jakarta-servletapi-5/jsr154/, complete with a build file). Yoav Shapira Millennium Research Informatics >-Original Message- >From: Endre Stølsvik [mailto:[EMAIL PROTECTED] >Sent: Friday, August 13, 2004 5:27 AM >To: Tomcat Users List >Subject: Re: SOLVED: How to get the context path for a web application? > >On Thu, 12 Aug 2004, Jacob Kjome wrote: > >| To get the context path at init time, try this > >Thanks..! Good to see that others (log4j!!) have this problem! > However, I have been thinking along these lines (the second idea >presented) already, but it then again boils down to that you really cannot >assume anything about what environment you're within. See, typically in >the development environements we use, the dirname of the webapp have >nothing in common with the "mount name" (you specify that in the tomcat >server config file, or these other "xml-snippets" outside of the file) - >thus I'm back to the starting point: no knowledge! > >If only the SerlvetContext object would be so nice as to have a simple >method getContextPath(), we'd all be happy! > >Endre > > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
On Fri, 13 Aug 2004, Shapira, Yoav wrote: | Hi, | And of course, since you can get the source for JSR154, there's nothing | preventing you from adding this method and running with a custom servlet | jar in your container. (It's at | http://cvs.apache.org/viewcvs.cgi/jakarta-servletapi-5/jsr154/, complete | with a build file). Hehe! "Forking" the JSR, that'd be a little hefty, don't you think? ;) Ask customers to dig up the servlet.jar from their chosen Servlet Container, replace it with this special one, binary-patch the potentially obfuscated class-files to implement this method, and -then- deploy the application. Yeah, why not..! I think I'd rather use one of the hacks suggested here, or simply configure it in web.xml or similar, as you already suggested. But, why wouldn't all be happy? And why isn't it simple? Endre - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
Per the servlet spec, a j2ee app isn't required to have an app path. The entire war file can be deployed remotely and run without ever being unpacked. In a case like that, there would be no path to the application. On Friday 13 August 2004 10:01 am, Endre Stølsvik wrote: > But, why wouldn't all be happy? And why isn't it simple? -- Ben Souther F.W. Davison & Company, Inc. This e-mail message, and any accompanying documents, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure, distribution or copying is prohibited. If you are not the intended recipient, please contact our office by email or by telephone at (508) 747-7261 and immediately destroy all copies of the original message. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
Hi, Don't even bother continuing this thread, it's pointless. Please address all Spec-related questions and comments to the Expert Group. That's why they exist. Some people just want to debate things forever and feel like their own use-cases have to be global just because... Yoav Shapira Millennium Research Informatics >-Original Message- >From: Ben Souther [mailto:[EMAIL PROTECTED] >Sent: Friday, August 13, 2004 10:12 AM >To: Tomcat Users List >Subject: Re: SOLVED: How to get the context path for a web application? > >Per the servlet spec, a j2ee app isn't required to have an app path. >The entire war file can be deployed remotely and run without ever being >unpacked. In a case like that, there would be no path to the application. > > > >On Friday 13 August 2004 10:01 am, Endre Stølsvik wrote: >> But, why wouldn't all be happy? And why isn't it simple? > >-- >Ben Souther >F.W. Davison & Company, Inc. > > >This e-mail message, and any accompanying documents, is for the sole use of >the intended recipient(s) and may contain confidential and privileged >information. Any unauthorized review, use, disclosure, distribution or >copying is prohibited. If you are not the intended recipient, please >contact our office by email or by telephone at (508) 747-7261 and >immediately destroy all copies of the original message. > >- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SOLVED: How to get the context path for a web application?
I'm never sure why smart people get this confused. ContextPath... has nothing whatsoever to do with running in a WAR, from a database, or exploded from a file system. For simple little things that an application might want to do like, oh, I don't know... reminder emails that might contain a link to the webapp in question. At that point, there is no request, since this is probably a scheduled occurrence. I suppose rather than use a scheduler, I could use cron and wget to hit a URL, in which case, voila, I'd have a HttpServletRequest. But wouldn't it be great if you could do application.getContextPath()? But alas, the expert group feels the answer is 'no'. Fine, whatever. It seems ridiculous that the application should not know anything about "who it is", or "under what URL/I I'm running" or "however you want to think of it", until an HttpRequest arrives on the scene. I just couldn't let it pass without pointing out that the one (contextPath) has nothing to do with the reasons that are normally cited for its exclusion from anything but HttpServletRequest. > -Original Message- > From: Ben Souther [mailto:[EMAIL PROTECTED] > Sent: Friday, August 13, 2004 9:12 AM > To: Tomcat Users List > Subject: Re: SOLVED: How to get the context path for a web > application? > > > Per the servlet spec, a j2ee app isn't required to have an > app path. The entire war file can be deployed remotely and > run without ever being > unpacked. In a case like that, there would be no path to the > application. > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
>contextPath = path.substring(0, path.lastIndexOf("/")); >contextPath = contextPath.substring(contextPath.lastIndexOf("/") + 1); This looks like a reasonable hack, but isn't it true that the filesystem path and the context path don't have to match? For example, I can map "" to /webapps/ROOT can't I? Or map "/myapp" to "/webapps/somethingelse"? David - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SOLVED: How to get the context path for a web application?
Quoting David Wall <[EMAIL PROTECTED]>: > >contextPath = path.substring(0, path.lastIndexOf("/")); > >contextPath = contextPath.substring(contextPath.lastIndexOf("/") + > 1); > > This looks like a reasonable hack, but isn't it true that the filesystem > path and the context path don't have to match? For example, I can map "" to > /webapps/ROOT can't I? Or map "/myapp" to "/webapps/somethingelse"? > > David The path returned by context.getResource("/") has nothing whatsoever to do with the file system. By your logic, my app located at "C:\apps\myappbuld\target\war", using said method above, would end up with the value "war". Yet, it ends up with whatever I set the "path" to in my context configuration file. If you want to continue to challenge this, do the test yourself. If you find something different than what I describe, let me know. Jake - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]