session不能被覆盖是怎么回事

wxshushude 2008-04-15 10:36:55
我在做一个注册模块,在我的action中我在session中加入了个username的属性值为登录的用户名,当用户注册成功后,跳到在个人信息页面,显示个人信息。但我在测试时我发现当我注册了多个用户时,在后来的注册的用户的个人信息页面会显示在其之前的注册的用户的个人信息。


在网上收了下,说可能是在当我在注册的其它用户时session中的username没清除。我又在action中加入request.getSession().removeAAttribute("username");但发现还是无法解决显示多个用户的信息的错误。
我在网上看了写资料说当session中有同名的属性时,其值会用后来的值覆盖先前的值。

我检查了我的request的属性user,我是在注册action中当用户数据插入数据库成功后,才将user(用户信息)加入request的user属性,按期望应该只读出当前注册的用户的信息,而且也应该只有当前的的用户的信息。

请问通常导致出现这种情况的原因是什么?有谁知道我还可以用什么方法去确定错误的地方?



...全文
269 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxshushude 2008-04-15
  • 打赏
  • 举报
回复
我把action的源文件和页面发上来,请大家看看
wxshushude 2008-04-15
  • 打赏
  • 举报
回复
*********************************person页面************************************************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />

<title>person我的账号</title>

</head>

<body leftmargin=0 rightmargin="0" topmargin="0" bottommargin="0">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><!-- head -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><jsp:include page="head2.jsp"></jsp:include>
</td>
</tr>
</table>
</td>
</tr>
<tr><td></td></tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><!-- left -->
<table border="0" cellpadding="0" cellspacing="0">
<logic:equal value="gameuser" name="type" scope="session">
<tr><td><jsp:include page="person_left.html" flush="true"></jsp:include><br><br></td></tr>
</logic:equal>
<logic:equal value="agent" name="type" scope="session">
<tr><td><jsp:include page="swhz_left.html" flush="true"></jsp:include>
<br><br></logic:equal>
</table>
</td>
<td>   </td>
<td align="right"><!-- right -->
<table border="0" cellpadding="0" cellspacing="0">
<logic:equal value="gameuser" name="type" scope="session">
<logic:present name="client">
<logic:notEmpty name="client">
<logic:iterate id="client" name="client" type="com.website.struts.entity.GameUser">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img border="0" src="person/wlcome.gif">
</td>
<td align="right">
<bean:write property="username" name="client"/>
<a href="#"><span style="font-size:20px;font-color:red">注销</span></a><td>
</tr>
</table>
</td>
</tr>
<tr><td><img border="0" src="person/secanttop.gif"></td></tr>
<tr><td>
<table border="0" cellspacing="0" cellpadding="6">
<tr><td align="center">用户账号:<bean:write property="username" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">昵称:<bean:write property="nickname" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">性别:<bean:write property="sex" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">年龄:<bean:write property="age" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">电子邮箱:<bean:write property="email" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">联系电话:<bean:write property="phone" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">角色图片: <img border="0" src="<bean:write property="role" name="client"/>" width="200px" height="200px"><br><br></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center"><a href="<%=request.getContextPath()%>/modify.jsp?username=<bean:write property="username" name="client"/>">修改信息</a><br><br></td><td><br><br></td></tr>
</table>
</td></tr>
</logic:iterate>
</logic:notEmpty>
</logic:present>
</logic:equal>
<logic:equal value="agent" name="type" scope="session">
<logic:present name="client">
<logic:notEmpty name="client">
<logic:iterate id="client" name="client" type="com.website.struts.entity.Agents">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img border="0" src="person/wlcome.gif">
</td>
<td align="right">
<bean:write property="username" name="client"/>
<a href="#"><span style="font-size:20px;font-color:red">注销</span></a><td>
</tr>
</table>
</td>
</tr>
<tr><td><img border="0" src="person/secanttop.gif"></td></tr>
<tr><td>
<table border="0" cellspacing="0" cellpadding="6">
<tr><td align="center">用户账号:<bean:write property="username" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">代理商编号:<bean:write property="acode" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">所在城市:<bean:write property="location" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">联系电话:<bean:write property="phone" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">电子邮件:<bean:write property="email" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">真实姓名:<bean:write property="realname" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">申请理由:<bean:write property="reason" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">曾从事情况:<bean:write property="experise" name="client"/></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center">个人照片:<img border="0" src="<bean:write property="pic" name="client"/>" width="200px" height="200px"></td></tr>
<tr><td align="center"><img border="0" src="person/secantbottom.gif"></td></tr>
<tr><td align="center"><a href="<%=request.getContextPath()%>/modify.jsp?username=<bean:write property="username" name="client"/>">修改信息</a></td><td></td></tr>
</table>
</td></tr>
</logic:iterate>
</logic:notEmpty>
</logic:present>
</logic:equal>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html:html>
*********************************person end************************************************
wxshushude 2008-04-15
  • 打赏
  • 举报
回复
*************************action*******************************************

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
AgentsForm agentsForm = (AgentsForm) form;// TODO Auto-generated method stub

request.getSession(true).removeAttribute("type");
request.getSession(true).removeAttribute("username");
request.removeAttribute("client");
request.getSession(true).removeAttribute("oldpath");
request.getSession(true).setAttribute("type", "agent");
Agents agents = new Agents();
agents.setUsername(agentsForm.getUsername());
agents.setPassword(agentsForm.getPassword());
try {
agents.setLocation(new String(agentsForm.getLocation().getBytes("ISO-8859-1"),"gb2312"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
agents.setPhone(agentsForm.getPhone());
agents.setEmail(agentsForm.getEmail());
try {
agents.setRealname(new String(agentsForm.getRealname().getBytes("ISO-8859-1"),"gb2312"));
agents.setReason(new String(agentsForm.getReason().getBytes("ISO-8859-1"),"gb2312"));
agents.setExperise(new String(agentsForm.getExperise().getBytes("ISO-8859-1"),"gb2312"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
agents.setRegtime(agentsForm.getRegtime());
agents.setPic("picture/agent/"+upload.getFilePath(agents.getRegtime(), agentsForm.getFile()));
boolean up_result = upload.uploadfile(agents.getRegtime(), agentsForm.getFile(), request);
AgentsDAO agentsDAO = new AgentsDAO(getDataSource(request,"mysql"));
boolean result = agentsDAO.insert(agents);
if(result && up_result){
list.add(agents);
request.getSession(true).setAttribute("username", agents.getUsername());
request.getSession(true).setAttribute("oldpath",agents.getPic());
request.setAttribute("client", list);
return mapping.findForward("user");
}else{
return mapping.findForward("suc");
}
}



*********************************action end***********************************************
wxshushude 2008-04-15
  • 打赏
  • 举报
回复
客户机的的internet选项的临时文件的设置是自动
a2048 2008-04-15
  • 打赏
  • 举报
回复
看看客户电脑ie浏览器的internet选项-->internet临时文件里的设置是否没有选自动.
你的问题好象和
http://topic.csdn.net/u/20080415/09/adc34a2b-e234-43ac-8f4c-06d57439ad94.html

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧