读书人

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

发布时间: 2012-11-03 10:57:43 作者: rapoo

关于拦截器中对接口方法的使用的请教
我们知道每个用户登录都会相应的产生一个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();

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

希望有兴趣或有这种经验的一起来探讨解决下 1 楼 uffeng 2007-08-20 我也遇到和你一样的问题!!
主要问题是 调用DAO (我是调用DAO)层的时候!数据库的链接实例没有打开!!
拦截器有参数!<param></param> 中间有一个@符号!我在找这是什么意思!

读书人网 >软件架构设计

热点推荐