JavaWeb -- http-equiv=refresh跳转的时候出现Session 丢失, 解决办法。。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="5;url='${pageContext.request.contextPath}/index.jsp'">    (1)
<title>全局消息显示页面</title>
</head>
<body>
<font size="16px" color="red">
 ${message}  ${user} <br/>
 <a href="${pageContext.request.contextPath}/index.jsp">5秒后自动跳到首页,如果没有跳转,请点击此处!!</a>  (2)
</font>
</body>
</html>

做注册登录功能的时候遇到一个奇怪的问题,注册成功后跳到 以上页面, 显示“注册成功 ”5秒后跳转到首页。

但是自动跳转到首页后 取Session里面的User信息的时候 ,发现为空。

不等5秒,直接点击超链接 进入首页,却发现 Session里面的信息 能够正常显示。

Session保存方式如下:

	HttpSession session = request.getSession();
	String sessionID = session.getId();  
	Cookie cookie = new Cookie("JSESSIONID", sessionID);     
	cookie.setPath(request.getContextPath());  
	cookie.setMaxAge(30*60);     //设置保存时间,不然关闭浏览器即销毁相应的Cookie   
	response.addCookie(cookie);  
	session.setAttribute("user", user);

 

引发原因不明, 但是解决方法如下, 修改浏览器隐私等级即可。

posted @ 2013-12-03 14:50  今晚打酱油_  阅读(541)  评论(0编辑  收藏  举报