当用户 session 过期时,使用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 不会在 session 过期时调用
最佳答案
使用 HttpSession.invalidate() 强制 session 失效您可以看到系统输出已打印,或者通过在 web.xml 中指定如下所示等待 session 自动过期。
<session-config>
<session-timeout>5</session-timeout>
</session-config>
关于java - 当用户 session 过期时,如何使用java更新数据库行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11863491/