@WebListener Annotation for monitoring

Source: Internet
Author: User

1. Create Dynamic Web Project, Dynamic Web module version Select 3.0

2. Add metadata-complete= "false" to the auto-generated Web. XML configuration

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Javaee:web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" 3 xmlns= "Http://Java.sun.com/xml/ns/javaee"4 Xmlns:javaee= "Http://java.sun.com/xml/ns/javaee" 5 Xmlns:web= "Http://java.sun.com/xml/ns/javaee" 6 xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"7 Metadata-complete= "false"version= "3.0">8<Javaee:display-name></Javaee:display-name>9<javaee:welcome-file-list>Ten <Javaee:welcome-file>Index.html</Javaee:welcome-file> One</javaee:welcome-file-list> A </Javaee:web-app>

3. Create a listener class to add annotations to the head of the Listener class @WebListener

Package Com.xhkj.listener;
Import Javax.servlet.servletcontextevent;import Javax.servlet.servletcontextlistener;import Javax.servlet.annotation.WebListener; @WebListenerpublic class Myservletcontextlistener implements Servletcontextlistener {@Override public void contextdestroyed (Servletcontextevent sce) { System.out.println ("=========================== Myservletcontextlistener destruction "); } @Override public void contextinitialized (Servletcontextevent sce) { System.out.println ("================== =========myservletcontextlistener initialization "); System.out.println (Sce.getservletcontext (). Getserverinfo ());} }

4. Start the Tomcat service. Printing results are as follows

5 precautions, each time you modify the configuration or Java code, you want to recompile, otherwise it will not work

  

@WebListener Annotation for monitoring

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.