在我的登录工作中,我使用身份验证 jsp 页面,将最大非 Activity 时间设置为 60,以防止单个用户名多次登录。
我在数据库中创建了一个字段status
,因此当用户登录时,状态将处于 Activity 状态,并且其他用户无法从同一用户名登录。
现在我的问题是如何在 session 过期时将数据库中的状态设置为非 Activity 状态。
为了更新非 Activity 状态,我做了
login=(String)session.getAttribute("login");
PreparedStatement pt = con.prepareStatement("update authentication set status='inactive' where username='"+login+"'");
因此,当 session 过期时,登录将返回 null。请告诉我如何解决我的问题
最佳答案
使用HttpSessionActivationListener
public void sessionDidActivate(HttpSessionEvent se)
Notification that the session has just been activated.
public void sessionWillPassivate(HttpSessionEvent se)
Notification that the session is about to be passivated.
或
sessionCreated(HttpSessionEvent se)
Receives notification that a session has been created.
sessionDestroyed(HttpSessionEvent se)
Receives notification that a session is about to be invalidated.
关于java - session 过期时如何在数据库中插入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16352439/