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
- Both are interfaces from javax.servlet.http package.
- They are derived from ServletRequest and ServletResponse interfaces.
- Both objects are created and implicitly passed to the service() method of Servlet by container.
Observe their Hierarchies
A) Hierarchy of HttpServletRequest
B) Hierarchy of HttpServletResponse
- The job of HttpServletRequest is to receive data sent by Web client, like user name and password.
- 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.
- The job of HttpServletResponse is to send data to Web client.
- Also comes with many setXXX() methods to set properties to a Servlet.
- 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.