Java Servlet API
Java Servlet API contains two core packages:
Servlets implement the javax.servlet.Servlet interface. The javax.servlet package contains the generic interfaces and classes that are implemented and extended by all servlets. While the javax.servlet.http package contains the classes that are used when developing HTTP - specific servlets. The HttpServlet is extended from GenericServlet base class and it implements the Servlet interface. HttpServlet class provides a framework for handling the HTTP requests.
The javax.servlet.Servlet defines five methods:
1. service() metho called by servlet to handle the client request in a new thead. service() methos accepts ServletRequest and a ServletResponse ohjects as parameters. ServletRequest object represents the client request. It contains the data sent in name/value pairs. ServletResponse object is used to send the response to the client.
2. init() is called once when servlet is loaded. It is a good place to initialize global variables. This methos accepts ServletConfig as parameter which provides initialization arguments for the servlet.
3. getServletConfig() returns the ServletConfig object passed to init().
4. destory() is called when wervlet is unloaded from memory. This is a good place to clean up any resources(such as open files or database connections).
5. getServletInfo() returns a string with version, copyright informations etc.