This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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.
subject: RequestDispatcher
It's not a secret anymore!