JSP中的会话问题
我正在登录页面上设置和获取会话属性,当我注销页面并按后退按钮时,它会再次返回主页。
这是我的代码,
::::::::::::::::::::::::::**sessionaction.jsp**::::::::::::::::::::::::::::::::::::::
<%@page import="java.util.*" %>
<%
String str = request.getParameter("UserName");
session.setAttribute("sessUserName", request.getParameter("Password"));
%>
<%
if (session.getAttribute("sessUserName").equals(""))
{
response.sendRedirect("login.jsp");
%>
<%
}
else
{
response.sendRedirect("home.jsp");
}
%>
::::::::::::::::::::::::::**logout.jsp**::::::::::::::::::::::::::::::::::::::
<%@page import="java.util.*" %>
<%
//session.invalidate();
session.removeAttribute("sessUserName");
%>
You have logged out. Please
<a href="login.jsp"><b>Login</b></a>
请指导我。
I am setting and getting the session attributes on login page, when i logout the page and press the back button it goes to home page again.
Here is my code,
::::::::::::::::::::::::::**sessionaction.jsp**::::::::::::::::::::::::::::::::::::::
<%@page import="java.util.*" %>
<%
String str = request.getParameter("UserName");
session.setAttribute("sessUserName", request.getParameter("Password"));
%>
<%
if (session.getAttribute("sessUserName").equals(""))
{
response.sendRedirect("login.jsp");
%>
<%
}
else
{
response.sendRedirect("home.jsp");
}
%>
::::::::::::::::::::::::::**logout.jsp**::::::::::::::::::::::::::::::::::::::
<%@page import="java.util.*" %>
<%
//session.invalidate();
session.removeAttribute("sessUserName");
%>
You have logged out. Please
<a href="login.jsp"><b>Login</b></a>
Kindly guide me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
设置缓存头
如果
需要缓存控制元标记
Set Cache Headers
Also
if needed meta tags for Cache-Control
我相信根本原因是用户sje397已经建议(接受他的答案),我只是在这里阐述。原因是您的会话失效与您的login.jsp 中的代码不同步。
您正在从会话中删除该属性,这意味着以下代码
应更改为
“其他”:
后退按钮可能只是显示本地缓存中的主页。尝试禁用缓存 看看它是否有效。
Root cause, I believe, is already suggested by user sje397(accept his answer), I am only elaborating here. Reason is that your session invalidation is not in sync with the code in your login.jsp.
You are removing the attribute from session which means the below code
should be changed to
Others:
The back button might just be displaying the home page from its local cache. Try disabling the cache and see if it works.