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