• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways of getting a requestDispatcher :

1. RequestDispatcher view = request.getRequestDispatcher("result.jsp");

Here i can also use RequestDispatcher view = request.getRequestDispatcher("/result.jsp");

2. RequestDispatcher view = getServletContext().getRequestDispatcher("/result.jsp");

Here can i use RequestDispatcher view = getServletContext().getRequestDispatcher("result.jsp") or would it give me an error..saying the location has to start from root ??;
 
fadi aboona
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

you get a RequestDispatcher in two ways from the request or from the context. With the servlet context you MUST include the foward slash because you can't specify a path relative to the current resource (the one that received this request.

Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic