it is a comment to the http://www.coderanch.com/t/168478/java-Web-Component-SCWCD/certification/Relative-url-Relative-path
relative urls for the HttpResponse's sendRedirect method:
The forward slash at the beginning means "relative to the root of this web app" (in this case, the web app is "myApp").
correct according to the Servlet API:
If the location is relative with a leading �/� the container interprets it as relative to the servlet container root.
causes a "The requested resource (...) is not available." error.
It should be:
The same rule is applied to the:
HttpResponse's encodeURL() and encodeRedirectURL() methods, it means the "/myApp" is not appended to the url.
For the rest (as <jsp:forward../>, <c:redirect../>, ServletRequest's getRequestDispatcher()...) the rule is:
If the path begins with a "/" it is interpreted as relative to the current context root.
relative to the current context root = relative to the root of the current web app.
If the location is relative without a leading �/� the container
interprets it as relative to the current request URI. If the location is relative with a leading �/� the container interprets it as relative to the servlet container root.
can somebody pls explain what "relative to the current request URI " &
"relative to the servlet container root" means .. with an example preferably pls .
I think you're talking about a known errata in the book...
Third hand-written note from the top should read:
The forward slash at the beginning means "relative to the root of the web container."
The last paragraph (and code) should read:
The Container builds the complete URL relative to the web container itself, instead
of the original relative to the original URL of the request. So the new URL will be:
Fourth hand-written note from the top should read: See... the
"myApp/cool" part of the path isn't here this time.
Does that clear up your issues?
Originally posted by Mike Gershman:
What exactly does "relative to the web container" mean?
That phrase means that if the web container is processing requests from the path that begins http://www.example.com/... *and* the web container hosts multiple webapps (such as 'myApp', 'admin', 'coolStuff'), then if a servlet from myApp (request URI of http://www.example.com/myApp/cool/bar.do) does a sendRedirect("/admin/showStatus.jsp"); the web container will send the redirect response back to the web browser with the location path of http://www.example.com/admin/showStatus.jsp.
Does that help?
[ February 21, 2005: Message edited by: Bryan Basham ]
In your example, what was the URL-pattern? Is it "myApp", the beginning of the characters that are replaced by a relative URL that starts with / ?
If myApp was not the URL-pattern, how is the string "myApp" specified to the web container at init time?
I thought we weren't supposed to put the real web app names in the URLs for security reasons.