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中的配置需要配置的监听

 

 
   

                    com.zlkj.pub.SessionListener           

           1    

 
   

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

你可能感兴趣的:(java)