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 are the benefits of using servlet over cgi?
what is multiple server?
How can we invoke another servlet in a different application?
Difference between get and post in java servlets?
Tell us something about servletconfig interface.
What is servlet? Explain
How do you find out what client machine is making a request to your servlet
What are the types of an http request?
What is difference between get and post method?
Is dispatcher servlet a singleton?
Explain the difference between jsp and servlet?
What is meant by cookies?
How is the get () method different from the post() method?
What are the different mode that servlets can be used?
Can a jsp be called using a servlet?