Struts2 portlet 使用 CookieInterceptor 读取 cookie
我正在使用 JSR286、Struts2 在 WebSphere Portal 6.1.5 上为 portlet 创建 Web 应用程序 问题是我无法在 CookieInterceptor 中构建工作。 我在src/struts.xml中尝试过:
<package name="web-app-default" extends="struts-portlet-default , json-default" abstract="true">
<interceptors>
<interceptor name="superInterceptor" class="ru.app.SuperInterceptor" />
<interceptor-stack name="ekp-cookie-stack">
<interceptor-ref name="cookie">
<param name="cookiesName">my-filter-cookie</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="portletDefaultStack" />
<global-results>
<result name="error">/jsp/common/error.jsp</result>
</global-results>
</package>
并且操作:
public abstract class EventGeneralAction extends GeneralAction implements CookiesAware{
//some code...
/** {@link CookieInterceptor} should inject ekp-filter-cookie. */
@SuppressWarnings("unchecked")
public void setCookiesMap(Map cookies){
LOG.trace("#setCookiesMap -> cookies[{}]", cookies);
this.cookies = cookies;
}
}
未调用方法setCookiesMap。 我用过 firebug,我真的看到,请求标头中有我的“my-filter-cookie”(使用 JQuery cookie 插件设置)。 Mozilla 的 WebDeveloper 显示浏览器有这样的 cookie,并且它将在 CURRENT_TIME+1 年后过期。
我尝试过另一种配置。我已经为操作编写了拦截器:
<!-- Shows events on desired day of year. ShowDayEventsAction is a subclass of EventGeneralAction -->
<action name="main" class="ru.app.ShowDayEventsAction" >
<interceptor-ref name="cookie">
<param name="cookiesName">my-filter-cookie</param>
</interceptor-ref>
<result>/jsp/event/view/day.jsp</result>
</action>
再次失败...?我做错了什么?拜托,建议一下。
I'm creating web-app using JSR286, Struts2 for portlets on WebSphere Portal 6.1.5
The problem is that I can't make work built in CookieInterceptor.
I've tried this in src/struts.xml:
<package name="web-app-default" extends="struts-portlet-default , json-default" abstract="true">
<interceptors>
<interceptor name="superInterceptor" class="ru.app.SuperInterceptor" />
<interceptor-stack name="ekp-cookie-stack">
<interceptor-ref name="cookie">
<param name="cookiesName">my-filter-cookie</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="portletDefaultStack" />
<global-results>
<result name="error">/jsp/common/error.jsp</result>
</global-results>
</package>
And the action:
public abstract class EventGeneralAction extends GeneralAction implements CookiesAware{
//some code...
/** {@link CookieInterceptor} should inject ekp-filter-cookie. */
@SuppressWarnings("unchecked")
public void setCookiesMap(Map cookies){
LOG.trace("#setCookiesMap -> cookies[{}]", cookies);
this.cookies = cookies;
}
}
The method setCookiesMap is not invoked.
I've used firebug, I really see, that request header has my "my-filter-cookie" in it (set using JQuery cookie plugin). WebDeveloper for Mozilla shows that browser has such cookie and it will be expired CURRENT_TIME+1 year.
I've tried another configuration. I've wrote interceptor for action:
<!-- Shows events on desired day of year. ShowDayEventsAction is a subclass of EventGeneralAction -->
<action name="main" class="ru.app.ShowDayEventsAction" >
<interceptor-ref name="cookie">
<param name="cookiesName">my-filter-cookie</param>
</interceptor-ref>
<result>/jsp/event/view/day.jsp</result>
</action>
Again fail...? What do I do wrong? Please, suggest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在:
由于“portletDefaultStack” ”不包含你的“ekp-cookie-stack”,那么cookie拦截器将不会被调用。基本上,您配置一个堆栈,然后告诉 Struts2 使用不同的堆栈。
试试这个:
您可能还想在
CookieInterceptor
的intercept
方法中设置断点,以确保它被正确调用。You are:
Since "portletDefaultStack" does not contain your "ekp-cookie-stack", then the cookie interceptor will not be invoked. Basically, you are configuring one stack and then telling Struts2 to use a different stack.
Try this:
You may also want to set a breakpoint in the
CookieInterceptor
'sintercept
method to make sure that it is being invoked properly.