One, the Servlet class Javax.servlet.http.HttpServlet; 1. is a singleton mode, with only one instance in a Web container. The server invokes its service method for request processing, and the service method calls Doget,dopost, respectively, based on the requested type. 2. Thread is unsafe because it is a singleton mode 3. The custom servlet inherits the HttpServlet and overrides the corresponding Doget methods. The method in the method body cannot call the parent class. Web. XML registration: <servlet> <servlet-name>myservlet</servlet-name> <servlet-class> com.zk.baseservlet.myservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name> Myservlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> Second, Filter Class Javax.servlet.Filter; 1. The filter first executes the Init method and initializes the read information from the filter configuration in Web. Xml. Executes only once. 2. Each request from the client goes through the Dofilter method. The filter must be configured to intercept the path. 3. Multiple filter execution process MyFilter1 beforeMyFilter2 beforeMyFilter3 beforeservlet doget methodMyFilter3 afterMyFilter2 AfterMyFilter1 after is a U-flow
Web. XML registration: <filter> <filter-name>myfilter1</filter-name> <filter-class> com.zk.basefilter.myfilter1</filter-class> </filter> <filter-mapping> < Filter-name>myfilter1</filter-name> <url-pattern>/*</url-pattern><init-param> <param-name>name</param-name><param-value>lisi</param-value></init-param> </filter-mapping> Listener class Servletcontextlistener listener is used to listen for and receive changes to the monitored objects 1. Container start notification The Contextinitialized method is called before the filter and servlet. The 2.contextDestroyed method is called after the container is closed and the filter and servlet are destroyed.
Not perfect place to welcome everyone to add
Java Web Component servlet, Filter, Listener