include() is a method defined in the RequestDispatcher interface with ServletRequest and ServletResponse as a parameter. It is same as forward with slight difference of storing the content of both source and target resource to the response object of the source servlet . Only matters is when we are calling include(), accordingly it adds the content to the response buffer and finally displayed to the browser. That means it dispatches the control to the target resource i.e servlet/jsp to include the processed data to the response object.

Signature of include()

include(ServletRequest, ServletResponse)

How to call include() method ?
It must be called with the RequestDispatcher object. And RequestDispatcher object is created by calling the getRequestDispacther() method by HttpServletRequest object. 


public void service(HttpServletRequest req, HttpServletResponse res) {

          ........
    RequestDispatcher rd = req.getRequestDispatcher("login.do"); 
    rd.include(req, res);

}

In the above code we are calling include with the RequestDispatcher object i.e "rd" and which includes the content of  "Login" servlet after processing the code of the service() method and returns the response object to the source servlet.




0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic