aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ Book and Errata Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ Book and Errata" Watch "HFSJ Book and Errata" New topic
Author

HFSJ Book and Errata

Ritesh Raman
Ranch Hand

Joined: Jun 20, 2005
Posts: 34
I am confused with HFSJ Book page no. - 204 and HFSJ errata for the
page no.- 136

HFSJ Book page 204
Topic - RequestDispatcher revealed


under the paragraph --
Getting a RequestDispatcher from ServletRequest---

RequestDispatcher view = request.getRequestDispatcher("result.jsp");

Here Book explain like --"if the path starts with a forward slash ("/"),the container sees that as 'starting from the root of this web app' "


Whereas HFSJ errata for page no. 136 explain forward slash ("/") as -

----------------------------------------------------------------------------
The last paragraph (and code) should read:
The Container builds the complete URL relative to the web container itself, instead of relative to the original URL of the request. So the new URL will be:
http://www.wickedlysmart.com/foo/stuff.html
----------------------------------------------------------------------------

Please explain forward slash ("/") - means
"relative to web app OR web container"


Thanks,<br />--------<br />SCJP 1.4
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

If there is a forward slash, then it is with respect to the ROOT of the web app. If it dosn't start with a /, then it is with respect to the current path, or the current folder.

Example,

A request comes in for test.jsp with the url http://localhsot:8080/myWebApp/Folders/TEST/test.jsp which is in the folder TEST and in the test.jsp, you are doing response.sendRedirect("testmeinstead.jsp") which is also inside TEST folder, then you the new url will be http://localhsot:8080/myWebApp/Folders/TEST/testmeinstead.jsp. But whereas, you say response.sendRedirect("/welcome.jsp"), then it means, go to the ROOT of this webapp which is http://localhsot:8080/myWebApp/ and then append the welcome.jsp there. So the final url for this will be http://localhsot:8080/myWebApp/welcome.jsp

Hope this is clear now.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Ritesh Raman
Ranch Hand

Joined: Jun 20, 2005
Posts: 34
Hi Jothi Shankar

Thanks for your reply, But i still confused with HFSJ Book and Errata

A/c to you "If there is a forward slash, then it is with respect to the ROOT of the web app."

Then in Book page no 136 The last paragraph (and code) is Right--

"relative to web app " So the new URL will be: - http://www.wickedlysmart.com/myApp/foo/stuff.html


whereas errata tells its wrong it should be --
"relative to the web container" So the new URL will be:- http://www.wickedlysmart.com/foo/stuff.html

please tell me Book is right or Errata on this regard ?
Ritesh Raman
Ranch Hand

Joined: Jun 20, 2005
Posts: 34
Hi Rancher,

any one please clear my doubt.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Both are correct, Ritesh.

In HFSJ, page 136 talks about response.sendRedirect but page 204 talks about request.getRequestDispatcher - which behave differently when a path begins with a leading "/".

RequestDispatcher is more intimate with the webapp and it just doesn't want to leave. It can't leave - how sweet of it! You've got to respect RequestDispatcher's loyalty!


A good workman is known by his tools.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ Book and Errata