Here is an interesting problem I am running into.

Say I have a servlet called "MyServlet". I am running xap out of a web 
application called "MyApplication".

>From code I want to send something to "MyServlet". What URL do I use?

In an html browser "/" is typically relative to the server URL. So if I do 
"/MyServlet" it will not resolve to http://localhost/MyApplication/MyServlet 
but instead http://localhost/MyServlet, which is not correct in this case.

I could make the request to /MyApplication/MyServlet, but that means my 
client-side code needs to know the name of the webapp.

Alternately we could expose the name of the webapp context and my code would 
append "MyServlet" to that.

>From a J2EE web-application perspective typically you are not hitting pages on 
>the server outside of the webapp, although it certainly is possible.

Note that this is an even more annoying problem if you have XML code like:

onCommand="/MyServlet?a=b"

In this case if I want to hit MyApplication/MyServlet I really have to hardcode 
that in the XML.

Possible solutions:

1: Leave it alone, they can hardcode in XML and append their URL to the context 
path in code.

2: Have at least optionally a flag or something like that that maps "/" to the 
root of the web application instead of the server root.

Ideas?

James Margaris

Reply via email to