Java Web Component servlet, Filter, Listener

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.