web 中关于清除session会话 中保存的对象的时候 执行删除语句操作

web 程序中删除当前用户的一系列操作在session失效之前执行

需要创建一个sessionLisenter 监听类 来监听当前客户端的session

 

package com.zlkj.pub;

import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener;

import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils;

import com.zlkj.dagl.bean.DrvVerifyTempInfo; import com.zlkj.dagl.bean.VehVerifyTempInfo; import com.zlkj.dagl.services.AmendArchivesService; import com.zlkj.dagl.services.VerifyArchivesService; import com.zlkj.frmwork.bean.UserSession; import com.zlkj.pub.database.ExcuteResult;

public class SessionListener implements HttpSessionListener{  /**   * 执行创建   */  public void sessionCreated(HttpSessionEvent arg0) {   // TODO Auto-generated method stub   System.out.println("=======================狼来了!!!!");  }  /**   * 执行销毁   */  public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {   // TODO Auto-generated method stub     //得取Session     // ServletContext servletContext = httpSessionEvent.getSession().getServletContext();     HttpSession servletContext = httpSessionEvent.getSession();         UserSession userSession = (UserSession) servletContext.getAttribute("userSession");             synchronized (this) {          System.out.println("用户是"+userSession);             if(userSession != null && !"".equals(userSession)){              String yhdh = userSession.getUser().getYhdh();              //System.err.println("sessionId="+yhdh);              //获取applicationContext上下文               WebApplicationContext webApplicationContext= WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext.getServletContext());              //获取审核              VerifyArchivesService  verifyArchivesService = (VerifyArchivesService) webApplicationContext.getBean("verifyArchivesService");              ExcuteResult resultDrv =  verifyArchivesService.deleteAllObjectVerifyTempInfo(new DrvVerifyTempInfo("",yhdh), "drvVerifyTempInfo");              ExcuteResult resultVeh =  verifyArchivesService.deleteAllObjectVerifyTempInfo(new VehVerifyTempInfo("",yhdh), "vehVerifyTempInfo");             }         }        }

}

 
 

web.xml中的配置需要配置的监听

 

<!-- session失效监听 -->   <listener>        <listener-class>            com.zlkj.pub.SessionListener        </listener-class>     </listener>

<!--设置失效时间 -->     <session-config>        <session-timeout>1</session-timeout>     </session-config>

 
 

绝对可以的 本人亲试了呵呵!希望您能用上哈

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值