如何在JSP中正确发送会话超时消息? [英] How to properly message a session timeout in JSP?

查看:104
本文介绍了如何在JSP中正确发送会话超时消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JSP的默认<session-timeout>设置,我想在会话过期后显示您的会话已过期(30分钟)"消息,并将用户带回登录页面.

Using the default <session-timeout> setting for JSP, I want to show an "Your session expired (30 min)" message after the session expire and bring the user back to the login page.

要使用((HttpServletRequest) request).getSession(false) == null来检测它未正确完成工作,因为在用户首次进入应用程序时会话将为null,从而使消息立即弹出.

To use ((HttpServletRequest) request).getSession(false) == null to detect it isn't doing the job properly, because the session will be null already at the first time the user enters the application, making the message pop right on.

如何避免这种情况?有没有一种方法可以自定义JSP的HttpSession,这样我就可以知道真正的事件何时发生?

How can I avoid this? Is there a way to customize JSP's HttpSession so I could know when the real event happened?

推荐答案

如何设置表示最后一次登录的cookie?如果cookie有效,并且URL不是登录URL,则可以显示会话超时消息.

How about setting a cookie indicating last login? If the cookie is valid and url is not login url, then the session timeout message can be shown.

这篇关于如何在JSP中正确发送会话超时消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆