HttpServletRequest vs HttpServletResponse

HttpServletRequest vs HttpServletResponse


Both HttpServletRequest and HttpServletResponse are inevitable in each Servlet, the Programmer write. Both exist in Servlet code as parameters to service() method. Even a Novice should be acquainted of these two interfaces.

List of Differences HttpServletRequest vs HttpServletResponse
  1. Both are interfaces from javax.servlet.http package.
  2. They are derived from ServletRequest and ServletResponse interfaces.
  3. Both objects are created and implicitly passed to the service() method of Servlet by container.

Observe their Hierarchies

A) Hierarchy of HttpServletRequest

HttpServletRequest vs HttpServletResponse

B) Hierarchy of HttpServletResponse

HttpServletRequest vs HttpServletResponse

  1. The job of HttpServletRequest is to receive data sent by Web client, like user name and password.
  2. Also comes with many getXXX() methods to retrieve other client information like client’s IP address, what protocol client used etc. and also include methods to know about the client’s browser like what is the name of the browser, its version etc.
  1. The job of HttpServletResponse is to send data to Web client.
  2. Also comes with many setXXX() methods to set properties to a Servlet.
  1. These being interfaces, the implementation of the abstract methods is to be developed by the Web server (like Tomcat or Jetty) developers. Even the servlet container is to be developed by the Web server developers.

Pass your comments and suggestions on the improvement of this tutorial on HttpServletRequest vs HttpServletResponse.

Know also the Difference between Servlet, GenericServlet, HttpServlet.

Leave a Reply

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