File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ ERRATA ??? pg 343

 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

please turn on to page 343.
the slash (/) in the Servlet(Controller) code is incorrect. A slash in the jsp's path should appear only if you are getting a request dispatcher form a ServletContext (as said on page 204). but on page 343 we are using a request to get a requestDspatcher. So as per my thinking ,
no / should appear in the jsp path

correct me if i am wrong
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't own the book but here's what the API says :

ServletRequest.getRequestDispatcher:
If the path begins with a "/" it is interpreted as relative to the current context root.

and

ServletContext.getRequestDispatcher:
The pathname must begin with a "/" and is interpreted as relative to the current context root.


You're probably misinterpretting the "must begin" and "if begins"
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wonder why other members who own the book and have gone thru it at least once, arent replying me.

guys please help me out !!!
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niranjan, above post as given by Satou is perfect explanation of your problem

Read the P204 of HFSJ again

This is what it says, I am typing it for you

Getting the RequestDispatcher from ServletRequest

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

The getRequestDispatcher() method in ServletRequest takes a String path for the resource to which you're forwarding the request.

If the path starts with a forward slash("/"), the container sees that as "starting from the root of this webapp".

If the path doesnot start with forward slash, its considered relative to original request.
 
Vijay Bharghav bheemineni
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Niranjan,

I totally agree with the explanation given by Gaurav.

We can get "RequestDispatcher" in two ways using "HttpServletRequest"
or "ServletContext" objects.

If we use "ServletContext" to get "RequestDispatcher", the path must start with "/", which means component exits in the path which is relative to root.

If we use "ServletRequest" to get "RequestDispatcher",the path it can start with "/" or relative to the request. If it starts with "/",it means the component exists in a location which is relative to root and if it does not start with "/", it means the component is placed relative to original request.

I hope this explanation clarifies your query.

Regards,
Vijay Bheemineni
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
_________________________________________________________________________
If we use "ServletRequest" to get "RequestDispatcher",the path it can start with "/" or relative to the request . If it starts with "/",it means the component exists in a location which is relative to root and if it does not start with "/", it means the component is placed relative to original request
_______________________________________________________________________

thanks guys, i never knew that whats said in the bold holds,
but i still have a query -

component is placed relative to original request

could any1 plz explainn this with a directory struture
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic