1 PackageSanglp.servlet;2 3 ImportJavax.servlet.ServletContext;4 Importjavax.servlet.ServletContextAttributeEvent;5 ImportJavax.servlet.ServletContextAttributeListener;6 ImportJavax.servlet.annotation.WebListener;7 8 /**9 * Created by Administrator on 2016/10/5.Ten * Monitor the Listener of attribute changes within the ServletContext range One */ A @WebListener - Public classMyservletcontextattributelistenerImplementsServletcontextattributelistener { - the @Override - Public voidattributeadded (servletcontextattributeevent servletcontextattributeevent) { -ServletContext application=Servletcontextattributeevent.getservletcontext (); - //get the added property name and property value +String name=servletcontextattributeevent.getname (); -Object value=Servletcontextattributeevent.getvalue (); +System.out.println (application+ "range added" +name+ "value for" +value+ "property"); A at - } - - @Override - Public voidattributeremoved (servletcontextattributeevent servletcontextattributeevent) { -ServletContext application=Servletcontextattributeevent.getservletcontext (); in //get the added property name and property value -String name=servletcontextattributeevent.getname (); toObject value=Servletcontextattributeevent.getvalue (); +System.out.println (application+ ") has removed the attribute" +name+ "with the value" +value+ "); - } the * $ @OverridePanax Notoginseng Public voidattributereplaced (servletcontextattributeevent servletcontextattributeevent) { -ServletContext application=Servletcontextattributeevent.getservletcontext (); the //get the added property name and property value +String name=servletcontextattributeevent.getname (); AObject value=Servletcontextattributeevent.getvalue (); theSystem.out.println (application+ "Scope" replaced the "+name+" value for the "+value+" property "); + - } $}
"Java EE Enterprise Application Combat Learning record" Mygetattributelistener