<repo_name>linsudeer/note-source<file_sep>/source-zh/src/com/servlet/demo/listener/MyContextLinstener.java
package com.servlet.demo.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.HashMap;
import java.util.Map;

@WebListener
public class MyContextLinstener implements ServletContextListener {

    private Map<String, String> conf = new HashMap<String, String>();

    @Override
    public void contextInitialized(ServletContextEvent evnt) {
        ServletContext sc = evnt.getServletContext();
        conf.put("contextPath", sc.getContextPath());
        // 保存一些全局的变量
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

        conf.clear();
    }
}
<file_sep>/source-zh/src/com/servlet/demo/listener/MySessionAttributeListener.java
package com.servlet.demo.listener;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

public class MySessionAttributeListener implements HttpSessionAttributeListener {
    @Override
    public void attributeAdded(HttpSessionBindingEvent httpSessionBindingEvent) {

    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent httpSessionBindingEvent) {

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent httpSessionBindingEvent) {

    }
}
