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 types of an http request?
What is Client-Server Computing?
What do you mean by httpservlet?
What is ServletConfig object?
What is meant by a servlet?
Is servlet synchronized?
List the Different types of servlet?
What is cgi and what are its drawbacks?
Tell the new features added in servletrequest interface i.e. Servlet 2.4
Can filter be used as request or response?
If a servlet is not properly initialized, what exception may be thrown?
how many jsp scripting elements are there and what are those?
Which event is fired at the time of project deployment and undeployment?
What is the importance of init() method in Servlet ?
When Servlet is unloaded?