The HttpServlet Class

You've seen that two prebuilt servlet classes are available for you to subclass, but so far, you don't know why you would choose HttpServlet instead of GenericServlet. The main difference between the two is that HttpServlet has extra methods and special request and response objects that are geared toward the HTTP protocol. The HttpServlet provides separate methods for handling the different types of HTTP requests (GET, POST, PUT, and so on). The two most common types of HTTP requests are GET and POST, which are handled by the doGet and doPost methods:

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException; protected void doPost(HttpServletRequest request, ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.