File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes RequestDispatcher 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 "RequestDispatcher" Watch "RequestDispatcher" New topic


Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
What is the difference between a RequestDispatcher object obtained from the Request object and the RequestDispatcher object obtained from the ServletContext ?

SCWCD 1.4, SCJP 1.4
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
The ServletRequest.getRequestDispatcher() method can accept paths relative to the current request (paths that don't start with a slash).

Paths passed to the ServletContext.getRequestDispatcher() method must start with a slash (and are therefore relative to the web app root.)
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
You MUST use context relative URLs with the one from the ServletContext (beginning with /), while you MAY use a URL relative to the current servlet (ommitting the /) as well as context relative with that from ServletRequest.
I agree. Here's the link:
subject: RequestDispatcher
It's not a secret anymore!