搞了一天了,怎么就不明白。action可获取,从拦截器跳至其他action都可获取浏览器,就是拦截器里的request的cookie都是空的
sruts2 配置文件<package name="weixin" namespace="/weixin" extends="struts-default">
   <interceptors>
     <interceptor name="weixinInterceptor" class="com.jd.pop.wxo2o.web.interceptor.WeixinInterceptor" />
     <interceptor-stack name="weixinStack">
         <interceptor-ref name="weixinInterceptor"></interceptor-ref>
         <interceptor-ref name="defaultStack"></interceptor-ref>
        </interceptor-stack>
    </interceptors>
        <action name="*" method="{1}" class="weixinAction">
            <result name="gotobind" type="redirect">/bind/bind.action</result>
            <interceptor-ref name="weixinStack"/>
        </action>
    </package>java 代码
HttpServletRequest request = (HttpServletRequest) actionInvocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
Cookie allCookie[]= request.getCookies();

解决方案 »

  1.   

    拦截器要实现ServletRequestAware接口,然后添加一个HttpServletRequest属性,这里给属性命名为request,
    重写方法:
    public void setServletRequest(HttpServletRequest request) {
    this.request = request;
    }
    然后通过这个request获取cookie。
      

  2.   

    Quote: 引用 1 楼 baohuan_love 的回复:

    拦截器要实现ServletRequestAware接口,然后添加一个HttpServletRequest属性,这里给属性命名为request,
    重写方法:
    public void setServletRequest(HttpServletRequest request) {
    this.request = request;
    }此法发帖前早已试过,无用
      

  3.   

     @Override
        public String intercept(ActionInvocation actionInvocation) throws Exception {
            ActionContext actionContext = actionInvocation.getInvocationContext();
            HttpServletRequest request= (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
            HttpServletResponse response = (HttpServletResponse) actionContext.get(StrutsStatics.HTTP_RESPONSE);
            System.out.println(request);
            System.out.println(response);
            return actionInvocation.invoke();
        }