This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes *** RequestDispatcher doubt *** Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "*** RequestDispatcher doubt ***" Watch "*** RequestDispatcher doubt ***" New topic
Author

*** RequestDispatcher doubt ***

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

component is placed relative to original request

please explain the above with a directory structure and URLs


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.
sarang bharambe
Ranch Hand

Joined: Apr 01, 2005
Posts: 40
Hey Niranjan,

As per servlet specs:

1. The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext.
This path must be relative to the root of the ServletContext
and begin with a �/�
2. The method uses the path to look up a servlet, using the
servlet path matching rules and returns the resulting object.
3. To allow RequestDispatcher objects to be obtained using relative
paths that are relative to the path of the current request (not
relative to the root of the ServletContext), the getRequestDispatcher
method is provided in the ServletRequest interface.
4. The servlet container uses information in the request object to
transform the given relative path against the current servlet to a
complete path.

For example, in a context rooted at �/� and a request to
/garden/tools.html, a request dispatcher obtained via
ServletRequest.getRequestDispatcher("header.html")
will behave exactly like a call to
ServletContext.getRequestDispatcher("/garden/header.html").

Hope this explains the whole thing.
Regards,
sarang


SCJP 1.4 (86%)<br />SCWCD 1.4 (86%)<br />----------<br />If You dont succeed at first time,call it Version 1.0 !!!
 
 
subject: *** RequestDispatcher doubt ***
 
Similar Threads
what is this for: setLocationRelativeTo()
HFSJ Book and Errata
HFSJ ERRATA ??? pg 343
ServletRequest RequestDispatcher
sendRedirect