contextsessionlistener.java

来自「Java的面向对象数据库系统的源代码」· Java 代码 · 共 170 行

JAVA
170
字号
// $Id: ContextSessionListener.java,v 1.1 2002/07/18 09:08:03 per_nyfelt Exp $package webapp;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;import javax.servlet.ServletContextAttributeListener;import javax.servlet.ServletContextAttributeEvent;import javax.servlet.http.HttpSessionAttributeListener;import javax.servlet.http.HttpSessionBindingEvent;import javax.servlet.http.HttpSessionEvent;import javax.servlet.http.HttpSessionListener;import org.apache.log4j.Category;import webapp.WebApp;/** * Listener for context-related and session-related application * events. Controls the state of the "WebApp" (which manages * "application global" objects like the database connection). * * @author James Stiefel * @version $Revision: 1.1 $ $Date: 2002/07/18 09:08:03 $ */public final class ContextSessionListener    implements ServletContextListener, ServletContextAttributeListener,                HttpSessionAttributeListener, HttpSessionListener {    /**     * log4j logger     */    private static Category logger = Category.getInstance(ContextSessionListener.class.getName());    /**     * Initialize the application and store in the context.     *     * @param event The servlet context event     */    public void contextInitialized(ServletContextEvent event) {        logger.info("contextInitialized()");        try {            WebApp.init();        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Clean up and close down the application     *     * @param event The servlet context event     */    public void contextDestroyed(ServletContextEvent event) {        logger.info("contextDestroyed()");        //close down the app        try {            // close the database connection            WebApp.term();        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Record the fact that a servlet context attribute was added.     *     * @param event The servlet context attribute event     */    public void attributeAdded(ServletContextAttributeEvent event) {        logger.info("attributeAdded('" + event.getName() + "', '" +            event.getValue() + "')");    }    /**     * Record the fact that a servlet context attribute was removed.     *     * @param event The servlet context attribute event     */    public void attributeRemoved(ServletContextAttributeEvent event) {        logger.info("attributeRemoved('" + event.getName() + "', '" +            event.getValue() + "')");    }    /**     * Record the fact that a servlet context attribute was replaced.     *     * @param event The servlet context attribute event     */    public void attributeReplaced(ServletContextAttributeEvent event) {        logger.info("attributeReplaced('" + event.getName() + "', '" +            event.getValue() + "')");    }    /**     * Record the fact that a servlet session attribute was added.     *     * @param event The session attribute event     */    public void attributeAdded(HttpSessionBindingEvent event) {        logger.info("attributeAdded('" + event.getSession().getId() + "', '" +            event.getName() + "', '" + event.getValue() + "')");    }    /**     * Record the fact that a servlet session attribute was removed.     *     * @param event The session attribute event     */    public void attributeRemoved(HttpSessionBindingEvent event) {        logger.info("attributeRemoved('" + event.getSession().getId() + "', '" +            event.getName() + "', '" + event.getValue() + "')");    }    /**     * Record the fact that a servlet context attribute was replaced.     *     * @param event The session attribute event     */    public void attributeReplaced(HttpSessionBindingEvent event) {        logger.info("attributeReplaced('" + event.getSession().getId() + "', '" +            event.getName() + "', '" + event.getValue() + "')");    }    /**     * Record the fact that a session has been created.     *     * @param event The session event     */    public void sessionCreated(HttpSessionEvent event) {        logger.info("sessionCreated('" + event.getSession().getId() + "')");    }    /**     * Record the fact that a session has been destroyed.     *     * @param event The session event     */    public void sessionDestroyed(HttpSessionEvent event) {        logger.info("sessionDestroyed('" + event.getSession().getId() + "')");    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?