Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Servlets and the fly likes RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher" Watch "RequestDispatcher" New topic


Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
When to use th servletContext and when to use request object?
Other than the URL Is there any diff between them?
RequestDispatcher rd = req.getRequestDispatcher("/anotherServlet");
rd.forward(req, res);
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I believe the ServletRequest.getRequestDispatcher(java.lang.String) and the ServletContext.getRequestDispatcher(java.lang.String) cannot access resources outside of the current servlet context, but you can use the ServletContext.getContext(java.lang.String) to obtain RequestDispatcher for resources outside of the current context.
I agree. Here's the link:
subject: RequestDispatcher