struts2 自定义拦截器 无法读取cookie

wubaoyu33 2015-05-07 03:07:44
搞了一天了,怎么就不明白。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();
...全文
126 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Reetmoon 2018-12-03
  • 打赏
  • 举报
回复
@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(); }
wubaoyu33 2015-05-11
  • 打赏
  • 举报
回复
没人遇到同样的情况吗
wubaoyu33 2015-05-07
  • 打赏
  • 举报
回复
[quote=引用 1 楼 baohuan_love 的回复:] 拦截器要实现ServletRequestAware接口,然后添加一个HttpServletRequest属性,这里给属性命名为request, 重写方法: public void setServletRequest(HttpServletRequest request) { this.request = request; } 此法发帖前早已试过,无用
  • 打赏
  • 举报
回复
拦截器要实现ServletRequestAware接口,然后添加一个HttpServletRequest属性,这里给属性命名为request, 重写方法: public void setServletRequest(HttpServletRequest request) { this.request = request; } 然后通过这个request获取cookie。

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧