Home > DeveloperSection > Interviews > What is Request Dispatcher?

Posted on    November-03-2014 11:10 PM

 Java Session 
Ratings:
 1 Answer(s)
  660  View(s)
Rate this:

Kamlakar Singh
Kamlakar Singh

Total Post:80

Points:400
Posted on    November-04-2014 12:10 AM

RequestDispatcher interface is used to forward the request to another resource that can be HTML, JSP or another servlet in same application. We can also use this to include the content of another resource to the response. This interface is used for inter-servlet communication in the same context.

There are two methods defined in this interface:

  1. void forward(ServletRequest request, ServletResponse response) – forwards the request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.
  2. void include(ServletRequest request, ServletResponse response) – includes the content of a resource (servlet, JSP page, HTML file) in the response.

We can get RequestDispatcher in a servlet using ServletContext getRequestDispatcher(String path) method. The path must begin with a / and is interpreted as relative to the current context root.


Don't want to miss updates? Please click the below button!

Follow MindStick