首页 > 代码库 > 监听器

监听器

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.toher.listener;

import cn.toher.bean.User;
import cn.toher.dao.UserLogDao;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 *
 * @author Administrator
 */
public class SessionListener implements HttpSessionListener {

    public SessionListener() {
    }

    ;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        HttpSession session = se.getSession();
        User user = (User) session.getAttribute("Suser");
// 监听session中的user,如果它为空,则去动作
if (user != null) { UserLogDao userLogDao = new UserLogDao(); userLogDao.addTimeout(user); } } }

 

监听器