关于拦截器中对接口方法的使用的请教

我们知道每个用户登录都会相应的产生一个session,在webwork中我们经常是把对象直接put该user对象进session.我们也可以通过这个session获取的该对象所有数据.
但是在该session中存在的对象是put()时的对象,而不是与数据库同步更新的对象,即当我们update数据库中的数据该session中的数据会保持不变.我所遇到的问题就是由此产生的。
我这两天发了一篇帖子关于单用户登录,具体算法与实践都已经实施完成。并且在单独的action中也测试过这个单用户登录的功能。可是当我准备把它写成拦截器时,因为上述的那个问题,致使拦截器中代码条件永远满足
[code]
public String intercept(ActionInvocation invocation) throws Exception {

Customer customer =(Customer) invocation.getInvocationContext().getSession().get("customer");

if(customer!=null){
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
String hashcode=session.getId();
if(hashcode!=null){

String hashcodetemp=customer.getPointcode();
if(hashcodetemp.equals(hashcode)){
ThreadLocalUser.set(customer);

String result = invocation.invoke();
ThreadLocalUser.set(null);
return result;
}
ActionContext.getContext().getSession().clear();
ActionSupport action = (ActionSupport) invocation.getAction();
action.addActionError("^o^你的账号已经在其它地方登录^o^");

return Action.LOGIN;
}
ActionSupport action = (ActionSupport) invocation.getAction();
return Action.LOGIN;
}
return Action.LOGIN;
}

[/code]
这就是我的拦截器代码 最主要的错误出现在这里
[code]

String hashcodetemp=customer.getPointcode();
[/code]
由于上述session中的问题,致使这个条件基本上永远满足。
因为只有这个customer对象是从数据库中查阅的,那么才能使得这个条件有判断作用。我也尝试过使用接口中的方法通过这个customerid来获得数据库中该对象.可一直达不到满足情况。另外我在测试action中测试过这个算法,具体代码如下,(效果成功)
[code]

HttpServletRequest request=(HttpServletRequest)ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);//获得requset
HttpSession session = request.getSession();
session.getId();
if(!session.getId().equals(customer.getPointcode())){
ActionContext.getContext().getSession().clear();
this.addActionMessage("^o^当前账户已经在其他地方登录,请重新登录^o^");
return INPUT;
}
[/code]
希望有兴趣或有这种经验的一起来探讨解决下
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值