Reputation: 703
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
Upvotes: 0
Views: 358
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
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