会话超时后如何重定向到指定页面
如何将用户重定向到他在会话超时之前已经打开的页面。
例如,用户打开/contactUs.jsp页面,然后会话超时并重定向到login.jsp页面,当他再次登录时如何将他重定向到contactUs.jsp页面?
How can I redirect the user to the page he has already opened before session time out.
For example the user was open /contactUs.jsp page, then the session time out and he redirects to the login.jsp page, how can I redirect him to contactUs.jsp page when he login again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以编写一个 过滤器 并检查会话属性是否存在于会话对象中。您必须在用户登录成功时添加/设置会话属性。
You may write a filter and check whether a session attribute is exists in the session object. You have to add/set session attribute at the time when user logged successfully.
您如何重定向到登录页面?此时,您应该将最初请求的 URL 存储在某处(可以在会话中,或者您传递的请求参数),以便在他再次登录后您可以重定向回那里
How are you redirecting to the login page? At that point you should store the originally requested URL somewhere (can be in session, or request param that you pass around) such that you can redirect back there after he logs in again
您必须使用登录 jsp 本身中的隐藏字段来完成此操作,因为服务器将无法识别用户,因为会话已经失效。
You'll have to do it using a hidden field in the login jsp itself, because the server won't recognize the user since the session has already been invalidated.
您可以将 JavaScript 刷新片段放入带有会话超时的响应页面中。
您还可以使用“刷新”字段 HTTP 标头。
参考:http://en.wikipedia.org/wiki/List_of_HTTP_header_fields 并搜索“刷新”
You can put an JavaScript refresh snippet into the response page with the timeout of the session's.
You can also use "Refresh" field HTTP header.
Refer to:http://en.wikipedia.org/wiki/List_of_HTTP_header_fields and search for "Refresh"