===========SessionListner.java========================
package com.martmunja.controller; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener; import org.springframework.web.servlet.ModelAndView; public class SessionListner implements HttpSessionListener{ @Override public void sessionCreated(HttpSessionEvent arg0) { // 세션 생성시 호출 HttpSession session = arg0.getSession(); long time = session.getCreationTime(); String id = session.getId(); System.out.println(time + "에 생성된 세션" + id); } @Override public void sessionDestroyed(HttpSessionEvent arg0) { // 세션 만료시 호출 HttpSession session = arg0.getSession(); long time = session.getCreationTime(); long last_time = session.getLastAccessedTime(); long now_time = System.currentTimeMillis(); String id = session.getId(); System.out.println((now_time - last_time) + "ms 만에 세션이 죽음" + id); } }
==========web.xml=============
<!-- Session config --> <listener> <listener-class>com.martmunja.controller.SessionListner</listener-class> </listener> <!-- Sessiong Time Config --> <session-config> <session-timeout>1</session-timeout> </session-config>