Howdy, You're missing a few things: 1. The context path is (according to the spirit of the servlet spec) to be decided by the server administrator, just like the port on which the webapp will run. Your application should be completely agnostic of the actual context path. This is not a design flaw in the servlet API, but a flaw in your own application's current design.
2. If you want to keep your current design, simply start the indexing thread when the first request comes in using its context path. You can, for example, have your servlet context listener class also be a servlet request listener, and do something on the first incoming request only. 3. This is a user, i.e. the tomcat-user list, question, so please continue discussion there. This list is for internal tomcat development discussions. Thanks, Yoav Shapira Millennium ChemInformatics >-----Original Message----- >From: Kent Boogaart [mailto:[EMAIL PROTECTED] >Sent: Tuesday, January 06, 2004 12:34 AM >To: '[EMAIL PROTECTED]' >Subject: Retrieving the context path from a standalone class > >Hi all, > >I have a class in my web app that runs in a separate thread. It's >responsibility is to re-index the site every x minutes (I am using Lucene >for site searches). It recursively loops over the relevant files within the >web app folder and attempts to index each one (the web app must be exploded >at this stage). I have this working for HTML and plain text resources. >However, I would like to include JSPs in my index. Of course, I need to >request each JSP to get any meaningful information for the index. > >I have a class that implements the ServletContextListener interface and >stores a global reference to the ServletContext object. Originally I >thought >this would be all I needed to dynamically request JSPs. I figured you could >retrieve the servlet context path from the ServletContext object in order >to >construct a URL to request - how silly of me! It seems you cannot retrieve >the context path from anywhere other than the HttpServletRequest interface. >Besides being a major design flaw (?), this complicates things for me. I >cannot dynamically construct a request URL because I don't know the context >path and my application must be able to run under any context path >including >the default one. > >I thought about using the ServletContext.getRequestDispatcher() method. >However, I needed an implementation of HttpServletRequest and >HttpServletResponse in order to use the dispatcher. HttpServletRequest, as >I >just mentioned, defines the getContextPath() method which I obviously can't >implement. The JSPs in my application already rely on this method returning >the correct context path. Hence, this was not an option. > >I also thought of having a servlet that loads on start-up set a global >variable containing the context path. However, I would need the servlet to >be requested in order to obtain an instance of HttpServletRequest from >which >I could extract the context path - the parameters to the init() method are >of no help. > >A possible solution is to define an environment entry for the web app that >duplicates the details of the context path. This is an awful solution and >should not be necessary. Can anyone shed some light on this? Am I missing >something embarrassingly obvious here? > >Thanks, >Kent > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] 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]