This article describes the basics of the servlet container. There are two servlet containers, the first one is simple, and the second is written according to the first. In order to make the first container as simple as possible, so did not do very complete. Some of the more complex servlet containers (including TOMCAT 4 and 5) can refer to other data.
The two servlet containers handle simple servlet and StaticResource. You can test it by using the Primitiveservlet in the webroot/directory. A complex servlet can exceed the capacity of these containers, and creating a complex servlet container is not the content of this article, so it is not covered here in detail.
The two application classes are encapsulated under the Ex02.pyrmont package. Before you understand how your application works, you must be familiar with the Javax.servlet.Servlet interface. Let's introduce this interface first. The details of the servlet container service servlet are then described.
Javax.servlet.Servlet interface
Servlet programming, you need to refer to the following two classes and interfaces: Javax.servlet and Javax.servlet.http, where the Javax.servlet.Servlet interface is particularly important in these classes and interfaces. All servlet must implement this interface or inherit the class that implements this interface.
The Servlet interface has five methods, as follows:
public void init(ServletConfig config) throws ServletException
public void service(ServletRequest request, ServletResponse response) throws ServletException, java.io.IOException
public void destroy()
public ServletConfig getServletConfig()
public java.lang.String getServletInfo()
The Init, service, and destroy methods are the Servlet lifecycle methods. When the servlet class is instantiated, the container loads init to notify the servlet that it has entered the service ranks. The Init method must be loaded for Servelt to receive and request. Programmers can override this method if you want to load a database driver, initialize some values, and so on. In other cases, this method is generally empty.