Forums Register Login

HFSJ Book and Errata

+Pie Number of slices to send: Send
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"
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
Hi Rancher,

any one please clear my doubt.
+Pie Number of slices to send: Send
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!
The City calls upon her steadfast protectors. Now for a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1202 times.
Similar Threads
SendRedirect() - 2 Forms of Relative URL's
clarification in the parameter of response.sendRedirect and request.getRequestDispatc
Relativ urls - mistake in HFS (page 136)
Doubt on sendRedirect()
HFSJ errata confusion
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:51:19.