1 3 package webapp; 4 5 import javax.servlet.ServletContextEvent ; 6 import javax.servlet.ServletContextListener ; 7 import javax.servlet.ServletContextAttributeListener ; 8 import javax.servlet.ServletContextAttributeEvent ; 9 import javax.servlet.http.HttpSessionAttributeListener ; 10 import javax.servlet.http.HttpSessionBindingEvent ; 11 import javax.servlet.http.HttpSessionEvent ; 12 import javax.servlet.http.HttpSessionListener ; 13 14 import org.apache.log4j.Category; 15 16 import webapp.WebApp; 17 18 19 27 28 public final class ContextSessionListener 29 implements ServletContextListener , ServletContextAttributeListener , 30 HttpSessionAttributeListener , HttpSessionListener { 31 34 private static Category logger = Category.getInstance(ContextSessionListener.class.getName()); 35 36 41 public void contextInitialized(ServletContextEvent event) { 42 43 logger.info("contextInitialized()"); 44 45 try { 46 47 WebApp.init(); 48 49 } catch (Exception e) { 50 e.printStackTrace(); 51 } 52 } 53 54 59 public void contextDestroyed(ServletContextEvent event) { 60 61 logger.info("contextDestroyed()"); 62 63 try { 65 66 WebApp.term(); 68 69 } catch (Exception e) { 70 e.printStackTrace(); 71 } 72 73 } 74 75 80 public void attributeAdded(ServletContextAttributeEvent event) { 81 82 logger.info("attributeAdded('" + event.getName() + "', '" + 83 event.getValue() + "')"); 84 } 85 86 91 public void attributeRemoved(ServletContextAttributeEvent event) { 92 93 logger.info("attributeRemoved('" + event.getName() + "', '" + 94 event.getValue() + "')"); 95 } 96 97 102 public void attributeReplaced(ServletContextAttributeEvent event) { 103 104 logger.info("attributeReplaced('" + event.getName() + "', '" + 105 event.getValue() + "')"); 106 107 } 108 109 114 public void attributeAdded(HttpSessionBindingEvent event) { 115 116 logger.info("attributeAdded('" + event.getSession().getId() + "', '" + 117 event.getName() + "', '" + event.getValue() + "')"); 118 } 119 120 121 126 public void attributeRemoved(HttpSessionBindingEvent event) { 127 128 logger.info("attributeRemoved('" + event.getSession().getId() + "', '" + 129 event.getName() + "', '" + event.getValue() + "')"); 130 } 131 132 133 138 public void attributeReplaced(HttpSessionBindingEvent event) { 139 140 logger.info("attributeReplaced('" + event.getSession().getId() + "', '" + 141 event.getName() + "', '" + event.getValue() + "')"); 142 } 143 144 145 146 147 152 public void sessionCreated(HttpSessionEvent event) { 153 154 logger.info("sessionCreated('" + event.getSession().getId() + "')"); 155 } 156 157 158 163 public void sessionDestroyed(HttpSessionEvent event) { 164 165 logger.info("sessionDestroyed('" + event.getSession().getId() + "')"); 166 167 } 168 169 } 170 | Popular Tags |