Types of communication between Servlets

There are two types of communication between servlets.

Application scoped data

  • The RequestDispatcher is called for the sharing of the data among the applications.
  • The forward method are used to process the requests and responses sent across the network.
  • The forward method send the HTTP request across Servlets and the request is processed by the target Servlet.
  • When the servlet engine calls the service method of an HTTP servlet, it passes two objects as parameters:
  • HttpServletRequest (the Request object)
  • HttpServletResponse (the Response object) 
  • Servlet communicates with the server and with the client through these objects.
  • Servlet reads the Request object from ServletInputStream
  • It can obtain information about client environment/server using request object and its method like GET and POST.
  • It also calls the response objects through setter method.

Session-scoped communication

  • HttpSession object is implemented along with the getAttribute() and setAttribute() methods for accessing of corresponding attributes of the objects.

Leave a Comment

Your email address will not be published. Required fields are marked *