搞了一天了,怎么就不明白。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();
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();
解决方案 »
- JAVA servlet import 报错
- 有关hibernate的jar包问题
- 关于上传到FTP,但是源路径的问题
- 菜鸟请教高手
- 困惑
- 请教webspher中hibernet的错误!
- struts如何往js中传递参数
- tomcat下jsp改名称后不能访问???
- 新手学Sturts2传值,遇到小问题,请各位帮忙解决~
- SpringMVC+myBatis配置 疑似properties文件没解析
- java编程:txt中两行字符串,无法正确存入Map中,总是有null值,不知道什么原因?
- java request.getContentLength()输出有值,但request.getInputStream().read()确等于-1
重写方法:
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
然后通过这个request获取cookie。
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();
}