1. Servlet is a Java program that can be deployed on a web server.
2. Servlet programming, need to reference the following two classes and interfaces: Javax.Servlet and Javax.Servlet.http, in these classes, javax.servlet.servlet interfaces are especially important. All servlets must implement this interface or inherit the class that has implemented this interface.
3. Servlet interface has five methods, as follows:
1) public void init (ServletConfig config) throws ServletException2) public void service (ServletRequest request, ServletResponseresponse) throws ServletException, java.io.IOException 3) public void destroy () 4) public ServletConfig getServletConfig () 5) public java.lang. String getServletInfo ()
4. Init, Service and Destroy methods are methods for the servlet lifecycle. When the Servlet class is instantiated, the container loads init to inform the servlet that it has entered the service row. The init method must be loaded and servel can receive and request. If you want to load a database driver, initialize some values, etc., programmers can override this method. In other cases, this method is generally empty.
The 5.Service method is called by the servlet container to allow the servlet to respond to a request. The servlet container passes the javax.servlet.servletRequest object and the javax.servlet.servletResponse object. The ServletRequest object contains client HTTP request information, and servletResponse encapsulates the servlet response. With these two objects, you can write some code that requires how to serve services and customers.
6. The container calls the Destroy method before removing the servlet instance from the service. When the servlet container is closed or the servlet container requires more memory, it calls it. This method is only called when all threads in the service method of the servlet are quit, or at timeouts will be called. After the Destroy method is called in the servlet container, it will no longer call the Service's service method.
The 7.DESTROY method gives the servlet opportunity to clear all free resources (such as memory, file processing, and thread) to ensure that the continuous state of the memory and the current status of the servlet is synchronized.