That is true, it is mostly a code issue. In code if you do something
like:

getNetService().retrieve("MyServlet")

We don't remember where the code was loaded from or do any path
manipulation like that. In XML it makes sense to remember where the XML
was loaded from and allow it to be relative, in code we can't really do
that. 

In code right now you have to do something like:

getNetService().retrieve(session._webappContext + "MyServlet");

It is kind of ugly by manageable I suppose. (We could clean up the
variable name and such.

James Margaris

-----Original Message-----
From: Coach Wei [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 06, 2006 10:31 AM
To: [email protected]
Subject: RE: URL resolution

Why can't you just do something like onCommand="MyServlet?a=b"? 

If the page is loaded from "MyApplication" webapps, any relative URL
should resolve to this webapp. In HTML, for example, if page1.html is
loaded from "/MyApp", any relative URL that page1.html uses would be
resolved to "/MyApp/relativeURL". I would we preserve this pattern. 

I do see one potential problem: If a page is loaded from "/MyApp/Pages",
then a relative URL such as "MyServlet" should be resolved to
"/MyApp/Pages/MyServlet" - which is clearly a problem. However, in this
case, the developer should reference to "MyServlet" via "../MyServlet"
instead. 

So my recommendation is to keep track of the URL of the page, and any
relative URL in this page should be resolved relatively to the page URL;
unless the URL is hardcoded to something else. 


> -----Original Message-----
> From: James Margaris [mailto:[EMAIL PROTECTED]
> Sent: Monday, November 06, 2006 3:55 AM
> To: [email protected]
> Subject: URL resolution
> 
> 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