user3380123
user3380123

Reputation: 703

Response parameter in requestdispatcher

When we forward a request from one servlet to another, using request dispatcher method forward, so as the other servlet generates the response, or when we want a response from the other servlet to go back to the one calling, we use include

  1. Now forward has two parameters, request and response ,request is client requestwhat is response? A response from servlet1 or servlet two?
  2. Same goes for include, what is in response object? Response from servlet 1, or servlet 2?

Upvotes: 0

Views: 358

Answers (2)

Yagnesh Agola
Yagnesh Agola

Reputation: 4657

From the Java Doc Reference :
1.For void forward(ServletRequest request,ServletResponse response)

request - a ServletRequest object that represents the request the client makes of the servlet
response - a ServletResponse object that represents the response the servlet returns to the client   

2.For void include(ServletRequest request,ServletResponse response)

request - a ServletRequest object that contains the client's request
response - a ServletResponse object that contains the servlet's response 

So in both the cases response is the object that use to write or send your servlet response to the client.
response is the object from the calling servlet passed to the caller servlet for further processing.

Please refer this link what is a request dispatcher it help you understand how it worked.

Upvotes: 0

Mitul Maheshwari
Mitul Maheshwari

Reputation: 2647

Request Dispatcher Defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server.

1) Forward :-

   Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.

2) Includes :-

   Includes the content of a resource (servlet, JSP page, HTML file) in the response.

For more information you can go through the following link.
RequestDispatcher

Upvotes: 1

Related Questions