Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Retrieving the context path from a standalone class

Retrieving the context path from a standalone class

2004-01-06       - By Kent Boogaart

 Back
Reply:     1     2     3     4     5     6     7     8     9     10     >>  

Hi Shapira,

Please see below for my responses.

Regards,
Kent



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.

[kb] OK, but how can my app be agnostic of the context path if I need to do
things like dynamically construct URLs? Why does the need to request a
resource in the same web app constitute a design flaw? Surely this is a
fairly common requirement . . . how else would I index dynamic resources?
Also, if the web app should be completely agnostic of the context path, why
does the HttpServletRequest interface define a method to retrieve it?

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.

[kb] Not entirely sure what you mean here. Are you saying I should write a
servlet that also implements ServletContextListener? If so, how do I
instigate the first request to the servlet (again, without knowing the
context path)? Wouldn't it make more sense to implement a filter and run the
index the first time the filter runs? The filter could pass the context path
to the indexing thread for subsequent usage. Of course, the indexing would
only take place once a request is received - I'd rather a solution that
allows the indexing to run on app startup.

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.

[kb] Sorry, I knew that - just wasn't thinking straight on a Tuesday evening
:-)

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: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)




©2008 junlu.com - Jax Systems, LLC, U.S.A.