• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relativ urls - mistake in HFS (page 136)

 
Gabriel Forro
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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:
from HFS:

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.


So the

causes a "The requested resource (...) is not available." error.

It should be:
 
Gabriel Forro
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have forgetten to add:

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.
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Confirmed from page 260 of the spec:

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.
 
Akshatha Nayak
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
Thank u
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am posting to repeat Akshatha's request. I have done quite a bit of googling and searching this board and I just find the same phrase "relative to the servlet container root". The servlet container root is a directory level. A URL is a text string. How do they relate? Please give us an example.

Thank you.
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Guys,

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:
http://www.wickedlysmart.com/foo/stuff.html

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?

- Bert
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bert:

What exactly does "relative to the web container" mean?

The web container is in a directory. The URL is a character string.

Thanks
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Gershman:
What exactly does "relative to the web container" mean?


Hi Mike,

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?

-Bryan
[ February 21, 2005: Message edited by: Bryan Basham ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Byran:

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.

Thanks
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic