What is the use of RequestDispatcher in servlet?
Answer Posted / kollu sreenivasa rao
When you want send your request to another servlet/jsp from
your servlet, we can use RequestDispatcher.
There are two ways to get reference of RequestDispatcher.
1)If you get requestdispatcher reference from
ServletContext, you have to specify the absolute url as
argument in getRequestDispatcher method like below.
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/my_other_app/servlet/SomeServlet");
dispatcher.forward(request, response);
2)If you get requestdispatcher reference from
ServletRequeset, you have to specify the relative url as
argument in getRequestDispatcher method like below.
RequestDispatcher dispatcher =
request.getRequestDispatcher("SomeServlet");
dispatcher.forward(request, response);
| Is This Answer Correct ? | 18 Yes | 11 No |
Post New Answer View All Answers
What is servlet and its types?
Tell us something about servletcontext interface.
What is Request Dispatcher?
Name the different ways of session tracking.
What is the difference between the servlets and cgi programs?
How do cookies work in servlets?
How to create war file?
Difference between get and post in java servlets?
What are the different ways we can maintain state between requests?
What are the life cycle methods of a servlet?
Which http method is said to be non-idempotent and idempotent?
What is the difference between genericservlet and httpservlet
What is the use of java servlet api?
Explain the jar and war files in servlet?
What are life cycle methods of a servlet?