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 is Client-Server Computing?

1899


What is url encoding and url decoding

590


Whether we can get deadlock situation in servlets?

578


What is session tracking?

699


What do you mean by session tracking?

675






What is the difference in between the httpservlet and generic servlet?

610


What's the servlet interface?

599


What are the type of protocols used in httpservlet?

617


What are sessions in servlets?

581


What are the common methods that are included in the http servlet class?

580


Describe some assignments that are executed by servlet container?

589


What is servlet mapping?

603


How can an existing session be invalidated?

668


Which protocol will be used by browser and servlet to communicate

584


What are the differences between forward() method and sendredirect() methods?

553