The Anatomy of a Servlet

As you just saw in the HelloWorldServlet, a servlet is a Java class that implements a few important methods. You can choose to implement these methods yourself or create a subclass of an existing servlet class that already implements these methods. The Servlet interface defines the methods that are required for a Java class to become a servlet. The interface definition is shown in Listing 13.2.

Code Listing 13.2. The Definition of the Servlet Interface
 package javax.servlet; public interface Servlet { public void destroy(); public ServletConfig getServletConfig(); public String getServletInfo(); public void init(ServletConfig config) throws ServletException; public void service(ServletRequest request, ServletResponse ...

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.