Howdy,

>[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?

The getContextPath method is there primarily to address HTML
restrictions (links).  Other ways to access dynamic resources revolve
around using the docBase as your reference, not the server root, and
include the RequestDispatcher calls and ServletContext#getResource
calls.  Both of these are agnostic of the context path as far as the
application developer is concerned, which is good design.

As you already mentioned, you can hack around this in various ugly ways,
e.g. including the context path as a context-param in web.xml.  This is
an easy out many people take.  But since you said you wanted to know the
clean approach, and I was glad to hear that, I'm trying to explain that
approach and the reasoning behind it.

>[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

No, that's not what I meant.  I meant exactly what I said, I'll try it
again without spaces when referring to servlet API classes: make your
ServletContextListener also a ServletRequestListener.  You will get
notified when the first request comes in.  At that time, you grab the
context path and store it so that your other classes can retrieve it
without needing an HttpServletRequest object.

A filter is also a possible solution, and there are several others.
Both the filter and the approach above will run the indexing on the
first request, which is not what you want.  (Although it's trivial to
tie a wget request to the server startup script).  Perhaps you can
modify your existing indexing class to use ServletContext#getResource
calls rather than whatever you're using now that requires the context
path.

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]

Reply via email to