日期:2014-05-18 浏览次数:20657 次
@WebListener public class MyContextListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { ServletContext context = sce.getServletContext(); //. . . } @Override public void contextDestroyed(ServletContextEvent sce) { //. . . } }
public class MyServletContextAttributeListener implements ServletContextAttributeListener { @Override public void attributeAdded(ServletContextAttributeEvent event) { //. . . event.getName(); //. . . event.getValue(); } @Override public void attributeRemoved(ServletContextAttributeEvent event) { //. . . } @Override public void attributeReplaced(ServletContextAttributeEvent event) { //. . . } }
@WebListener public class MySessionListener implements HttpSessionListener { @Override public void sessionCreated(HttpSessionEvent hse) { HttpSession session = hse.getSession(); //. . . } @Override public void sessionDestroyed(HttpSessionEvent hse) { //. . . } }
public class MyHttpSessionActivationListener implements HttpSessionActivationListener { @Override public void sessionWillPassivate(HttpSessionEvent hse) { // ... hse.getSession(); } @Override public void sessionDidActivate(HttpSessionEvent hse) { // ... } }
public class MyHttpSessionAttributeListener implements HttpSessionAttributeListener { @Override public void attributeAdded(HttpSessionBindingEvent event) { HttpSession session = event.getSession(); //. . . event.getName(); //. . . event.getValue(); } @Override public void attributeRemoved(HttpSessionBindingEvent event) { //. . . } @Override public void attributeReplaced(HttpSessionBindingEvent event) { //. . . } }
public class MyHttpSessionBindingListener implements HttpSessionBindingListener { @Override public void valueBound(HttpSessionBindingEvent event) { HttpSession session = event.getSession(); //. . . event.getName(); //. . . event.getValue(); } @Override public void valueUnbound(HttpSessionBindingEvent event) { //. . . } }
@WebListener public class MyRequestListener implements ServletRequestListener { @Override public void requestDestroyed(ServletRequestEvent sre) { ServletRequest request = sre.getServletRequest(); //. . . } @Override public void requestInitialized(ServletRequestEvent sre) { //. . . } }
ServletContainerInitializer.onStartup 将会在应用程序启动的时候调用: