1

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

所以,在这些情况下,如何更新数据库行。现在我在注销时使用以下代码点击条件

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() 但在那个 sessioncreated 被自动调用但 sessiondistroyed 不会在会话过期时被调用

4

1 回答 1

0

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

<session-config>
      <session-timeout>5</session-timeout> 
</session-config>
于 2012-08-08T11:58:47.283 回答