What Is a Servlet?
Aservlet is a Java programming language class that is used to extendthe capabilities of servers that host applications accessed by means of a request-responseprogramming model. Although servlets can respond to any type of request, they arecommonly used to extend the applications hosted by web servers. For such applications,Java Servlet technology defines HTTP-specific servlet classes.
Thejavax.servlet andjavax.servlet.http packages provide interfaces and classes for writing servlets. Allservlets must implement theServlet interface, which defines life-cycle methods. When implementing a genericservice, you can use or extend theGenericServlet class provided with theJava Servlet API. TheHttpServlet class provides methods, such asdoGet anddoPost, for handling HTTP-specific services.
This chapter focuses on writing servlets that generate responses to HTTP requests.