RequestDispatcher
is a interface of Servlet API. Implementation of which provided by vendors.
This interface provides methods for including contents of a resource (Such as
Servlet/html page etc.) to the response of current Servlet or forward the
request to another web resource(Such as Servlet/html page etc.).
Methods:
1- getRequestDispatcher():
Method of ServletRequest interface is used to obtain a RequestDispatcher object.
public RequestDispatcher getRequestDispatcher(String URL of Resource);
Method of ServletRequest interface is used to obtain a RequestDispatcher object.
public RequestDispatcher getRequestDispatcher(String URL of Resource);
RequestDispatcher interface provides include() and forward() method for including contents of a resource and to forward the request to another response respectively.
I) include():
Is used to include the content of the resource to the response of the current Servlet.
Is used to include the content of the resource to the response of the current Servlet.
public void include(ServletRequest,
ServletResponse) throws ServletException, IOException;
II) forward():
Is used to forward request to another resource.
public void forward(ServletRequest,
ServletResponse) throws ServletException, IOException;
Note:
Real life example (Cases for request handling):
Assume
counselor is acts as a Servlet
Case1:
Self give result if any one ask about course CourseName/fee/CourseDuration.
Case2:
For Some technical Enquiry (such as version of hibernate) ask the Technical Trainer ( Take a Help of another person on same enquiry) and then give the information (result).
Case3:
Forward the call direct to the Trainer (Now information (result) is produce by Trainer) . |
No comments:
Post a Comment