1. servlet is a Java program that can be deployed on the Web server.
2. For servlet programming, the following two classes and interfaces must be referenced: javax. servlet and javax. servlet. http. Among these classes and interfaces, javax. servlet. servlet interfaces are particularly important. All servlets must implement this interface or inherit the classes that have implemented this interface.
3. The servlet interface has five methods:
1) Public void Init (servletconfig config) throws servletexception
2) 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. The init, service, and destroy methods are servlet lifecycle methods. After the servlet class is instantiated, the container loads init to notify the servlet that it has entered the service column. The init method must be loaded, and the servelt can receive and request. To load the database driver and initialize some values, the programmer can rewrite this method. In other cases, this method is generally null.
5. The 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 javax. servlet. servletresponse object. The servletrequest object contains the HTTP request information of the client. The servletresponse encapsulates the servlet response. With these two objects, you can write code that requires servlet service and customer request.
6. The Container calls the destroy method before deleting the servlet instance from the service. When the servlet container is closed or the servlet container requires more memory, it is called. This method is called only when all threads in the servlet service method exit, or when it times out. After the servlet container calls the destroy method, it no longer calls the servlet service method.
7. the destroy method gives the servlet the opportunity to clear all idle resources (such as memory, file processing, and threads) to ensure that the continuous state of the memory and the current state of the servlet are synchronized.