当前位置:编程学习 > JAVA >>

struts2定义了一个拦截器结果得不到cookie的值 求解释

struts2定义了一个拦截器结果得不到cookie的值 求解释
拦截器中可以得到action方法里面的属性吗 比如插入一个对象 我怎么获得这个对象的值呢 Cookie Struts --------------------编程问答-------------------- 拦截器类和普通类没什么区别,
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession(); //session对象
HttpServletRequest request = ServletActionContext.getRequest();//request对象
        Cookie[] cookies = ServletActionContext.getRequest().getCookies(); //cookie对象 是浏览器的cookie


--------------------编程问答-------------------- 像CSDN这样的加载某个帖子的时候对应回复每个楼层的用户名和用户的头像 是不是根据存在帖子信息中的userID到用户信息表里查吗?哪样用户多的话 表大是一方面而且根据userID的话要每层楼都去查一遍啊。不知道怎么设计的。谁能指点迷津? --------------------编程问答--------------------
引用 楼主 liangchengfck1 的回复:
struts2定义了一个拦截器结果得不到cookie的值 求解释
拦截器中可以得到action方法里面的属性吗 比如插入一个对象 我怎么获得这个对象的值呢

 ActionContext actionContext = arg0.getInvocationContext();  
     HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);  
     Cookie[] cookies = request.getCookies();  
        if (cookies!=null) {  
            for (Cookie cookie : cookies) {  
                if ("back_userId".equals(cookie.getName())) {  
                 userId=Integer.valueOf(cookie.getValue());
                   System.out.println("拦截器得到的back_userId============"+userId);
                    }
                if ("back_userName".equals(cookie.getName())) {
                 userName=cookie.getValue();
                 System.out.println("拦截器得到的 back_userName============"+userName);
                 System.out.println("用户:"+userName+"执行了的方法名是========="+methodName);
                 }
                
            }
我是这样的 那页面怎么得打拦截器的值呢
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,