Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ Book and Errata

 
Ritesh Raman
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ritesh Raman
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rancher,

any one please clear my doubt.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic