web 中关于清除session会话 中保存的对象的时候 执行删除语句操作
2014-04-29 18:38
483 查看
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>
绝对可以的 本人亲试了呵呵!希望您能用上哈
需要创建一个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>
绝对可以的 本人亲试了呵呵!希望您能用上哈
相关文章推荐
- 【javaweb:session】session域对象中保存的数据在什么范围内有效?一次会话!!
- laravel5.4 关于执行删除管理员时候被删用户如果当时是登陆状态还可以操作的处理
- 关于session会话对象原理
- mybatis执行删除的restful操作的时候:Access to the specified resource has been forbidden.
- 使用sql语句建立与删除链接服务器及执行数据库操作
- oracle 中--怎么查看当前表空间在作什么操作?--查锁,死锁,当前执行时间长的Sql语句,没提交的事务,对象为哪些进程所用
- Session的基本介绍与操作:保存、更新、查看、删除
- 一次ORA-4030问题诊断及解决【解决思路不错,说明了对象的统计信息与优化器的优化操作(即选择执行一个SQL语句在该优化参数环境下最佳的执行计划)间的关系】
- 在SSH2开发平台下利用Hibernate Session对象执行原生Sql语句
- Mysql 将结果保存到文件 从文件中执行sql语句 记录操作过程(tee 命令的使用)
- 1.利用android提高的的insert,query,update,deleteAPI与execSql,rawQuery函数执行原生的插入,查询,更新,删除语句操作花费时间的对比结果
- Session_End()这个方法,为什么在会话结束的时候没有执行?
- java.security.cert.CertificateException: Selenium 自动化的时候调用API 执行操作引起的关于https的问题
- MyBatis-执行插入语句的时候返回主键ID到传入的参数对象中
- win 2003 / IIS6 部署网站的时候,文件IO操作、删除项目文件, 会导致IIS重启,Session丢失问题
- 集合已修改;枚举操作可能无法执行。使用foreach 循环删除DataRow的时候的问题! 该死的AcceptChanges() Row.elete() Remove(Row)使用不同。
- Struts2 获取WEB对象(作用域,request、application、session) 清除Session的值
- 关于C#和ASP.NET中对App.config和Web.config文件里的[appSettings]和[connectionStrings]节点进行新增、修改、删除和读取相关的操作
- 【JavaWeb-20】3种对象状态以及相互转化、一级缓存和快照、Session其他API、一对多配置和操作、cascade
- [原创]java WEB学习笔记31:会话与状态管理 session机制 概述(定义,session机制,session的声明周期,保存session的方式,Session的创建与删除)