aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ ERRATA ??? pg 343 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 "HFSJ ERRATA ??? pg 343" Watch "HFSJ ERRATA ??? pg 343" New topic
Author

HFSJ ERRATA ??? pg 343

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
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


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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"


[My Blog]
All roads lead to JavaRanch
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
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

Joined: Mar 04, 2006
Posts: 254
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

Joined: Aug 31, 2005
Posts: 29
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

Joined: Oct 16, 2005
Posts: 1277
_________________________________________________________________________
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HFSJ ERRATA ??? pg 343