2012-08-08 83 views
0

使用java如何在用户会话过期时更新数据库行? 这种情况包括 1.用户不点击任何注销按钮 2.如果自动关闭浏览器。 3.系统直接关机状态。如何在用户会话过期时使用java更新数据库行?

所以,在这些情况下如何使用下面的代码在注销点击condion

Connection con = (Connection) new DB2Connection().getDatabaseConnection(); 
if(request.getParameter("flrmdn") != null) 
{ 
String s1=request.getParameter("flrcaf"); 
String s2=request.getParameter("flrmdn"); 

String sql1="update table2 set FLRReference=0 where CAF='"+s1+"' and  MDN='"+s2+"' and FLRReference=1 "; 
Statement st1=con.createStatement(); 
int vupdate=st1.executeUpdate(sql1); 
} 
else if(request.getParameter("indexmdn") != null) 
{ 
String indexcaf=request.getParameter("indexcaf"); 
String indexmdn=request.getParameter("indexmdn"); 

String sql="update table set IndexReference=0 where CAF='"+indexcaf+"' and MDN='"+indexmdn+"' and IndexReference=1 "; 
Statement st=con.createStatement(); 
int entryrows=st.executeUpdate(sql); 
} 


// Redirecting user to actual required page 

if(request.getParameter("location").equalsIgnoreCase("login")) 
{ 
response.sendRedirect("login.jsp?logout=true"); 
} 

我已经使用httpsessionlistner(),sessioncreated(),sessiondistroyed(),但在可更新DB row.now IAM sessioncreated会自动调用,但会话过期时不会调用sessiondistroyed

+0

你怎么知道sessionDestroyed()没有被调用? – 2012-08-08 11:33:30

+1

我已经使用控制台消息会话创建和sessiondistroyed ..但会话创建消息打印evry时间,一个新的登录发生,但同一时间sessiondistroyed不会打印System.out.println消息,(这是在sessiondistroyed内使用。 ) – 2012-08-08 11:54:40

回答

0

使用HttpSession.invalidate()强制会话失效,您可以看到系统输出已打印或等待会话自动过期,方法如下所示,在web.xml中指定。

<session-config> 
     <session-timeout>5</session-timeout> 
</session-config> 
+0

如何在用户会话过期时更新数据库行?我已经写了HttpSession.invalidate(),但如果浏览器直接关闭什么情况下,它不会调用.... – 2012-08-08 12:05:03

+0

@Praveen - 这就是为什么你配置web.xml中的自动失效 – 2012-08-08 12:12:37

+0

kk现在它被设置为默认30分钟)..但是当我试图直接关闭浏览器...相应的数据库工作行不更新..我的意思是行更新为1锁定该用户,如果该用户不满足行,并没有点击注销按钮,该行应该分配给其他用户。即应该是'0' – 2012-08-08 12:29:21

相关问题