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


Please Help Members By Posting Answers For Below Questions

What are the types of an http request?

797


What is Client-Server Computing?

2079


What do you mean by httpservlet?

744


What is ServletConfig object?

814


What is meant by a servlet?

780


Is servlet synchronized?

802


List the Different types of servlet?

775


What is cgi and what are its drawbacks?

728


Tell the new features added in servletrequest interface i.e. Servlet 2.4

800


Can filter be used as request or response?

725


If a servlet is not properly initialized, what exception may be thrown?

845


how many jsp scripting elements are there and what are those?

776


Which event is fired at the time of project deployment and undeployment?

1043


What is the importance of init() method in Servlet ?

797


When Servlet is unloaded?

823