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.




Related Posts:

  • Servlet Life Cycle Life Cycle of Servlet starts when a servlet application get deployed in the web server. Web container is responsible for calling all the life cycle methods. Servlet has following three life cycle methods : 1. init() 2. serv… Read More
  • ServletContext Object in Servlet ServletContext is only a single object to a whole Servlet Application. It is once created and initialized by the web container at the container start-up. A Web application has many Servlet classes and for every servlet… Read More
  • What is a Web Container After developing Servlet Application we need to deploy and run our application at theWeb-Server. When a Web-server starts it internally starts a web-container which is also termed as servlet container.  What is a we… Read More
  • What Happens at Container Start-Up in Servlet There are many task happening internally inside the Web-Server. Following are the list of task performed at the container start-up : 1. Reads the web.xml file or Annotations specified on various web components and stores al… Read More
  • Introduction to Java Servlet Servlet is a web technology, which is used to develop web application. It is used to process the HTTP request by the client. Servlet was first introduced by the Sun MicroSystems with released of  version 1.0 in 1997. … Read More

0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201976

Online Members

Live Traffic