【发布时间】:2014-02-05 10:03:50
【问题描述】:
我的应用程序在 struts2 中。
我要求在会话中存储我的应用程序详细信息。我无法从会话中删除这些属性。登录后,我必须选择要处理的对象。现在我打开一个新选项卡并选择另一个工作对象。因此,我的第一个对象值被覆盖了。因此,如果在我的第一个选项卡中我做了一些工作,那么该操作会更新错误信息。
这就是我计划解决问题的方式。
我试图在拦截器类的 setter 方法中设置一个值,但我无法在我的 index.jsp 中访问该值。
这个拦截器被所有的action调用,index.jsp也包含在每个jsp中。
我将维护一个哈希表,该哈希表将存储用户 ID 和 40 个字符的随机字符串。这个 id 将是唯一的,在将 jsp 中存在的值与存储在 hastable 中的值进行比较后,我将更新 userid。
如果我发现该值匹配,那么我将生成另一个值并存储在 jsp 和 hastable 中。如果值不匹配,我将销毁会话。
请告知我该如何继续,或者是否有任何其他解决方法可以实现相同的目标。
代码 拦截器类
String strFrom = (String)aContext.get(ServletActionContext.ACTION_NAME);
HttpServletRequest httpReq = (HttpServletRequest)aContext.get(ServletActionContext.HTTP_REQUEST);
HttpSession session = httpReq.getSession();
String sessionValue = (String)httpReq.getSession().getAttribute("sessionValue");
String test = httpReq.getParameter("sessionValue");
if(strFrom.equals("ValidateUser")){
// Do nothing
}else if(sessionValue == null && strFrom.equals("HomePage")){
session.setAttribute("sessionValue", getRandomString(20));
}else if (sessionValue.equals(session.getAttribute("sessionValue"))){
session.setAttribute("sessionValue", getRandomString(20));
}else{
httpReq.setAttribute("message","Session Expired. Please Login Again");
return "loginAgain";
}
index.jsp
<body>
<s:hidden id="hidBidType" value="%{#session.tenderBidType}"/>
<s:property value="%{#session.sessionValue}"/>
<s:hidden name="sessionValue" id="sessionValue" value="%{#session.sessionValue}"/>
</body>
login.jsp
<form name="loginPage" method="post">
<s:hidden name="sessionValue" id="sessionValue" value="1"/>
</form>
【问题讨论】:
-
如果会话过期,您必须重新创建会话对象。