• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When to use th servletContext and when to use request object?
Other than the URL Is there any diff between them?
getServletConfig().getServletContext().getRequestDispatcher("/servlet/ViewMiniPoll").forward(req,res);
RequestDispatcher rd = req.getRequestDispatcher("/anotherServlet");
rd.forward(req, res);
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Craig
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic