File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Relativ urls - mistake in HFS (page 136) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Relativ urls - mistake in HFS (page 136)" Watch "Relativ urls - mistake in HFS (page 136)" New topic
Author

Relativ urls - mistake in HFS (page 136)

Gabriel Forro
Ranch Hand

Joined: Apr 16, 2004
Posts: 59
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
Gabriel Forro
Ranch Hand

Joined: Apr 16, 2004
Posts: 59
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

Joined: Mar 22, 2004
Posts: 275
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

Joined: Jul 15, 2004
Posts: 53
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


Only those who will risk going too far, Can possibly find out how far one can go! <br />happiness is journey and not destination<br /> <br />A Nayak<br />----------------------------------<br />SCJP 1.4<br />SCWCD 1.3<br />SCBCD 1.3
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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.


Mike Gershman
SCJP 1.4, SCWCD in process
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8764
    
    5
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


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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

Joined: Apr 30, 2001
Posts: 199
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

Joined: Mar 13, 2004
Posts: 1272
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relativ urls - mistake in HFS (page 136)
 
Similar Threads
SendRedirect() - 2 Forms of Relative URL's
SCWCD
'/' means root of what?
HFSJ Book and Errata
clarification in the parameter of response.sendRedirect and request.getRequestDispatc