Struts2 portlet 使用 CookieInterceptor 读取 cookie

发布于 2024-10-04 05:40:23 字数 2017 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坦然微笑 2024-10-11 05:40:24

您正在:

  • 定义一个名为“superInterceptor”的拦截器(不确定它适合在哪里)
  • 定义一个名为“ekp-cookie-stack”的拦截器堆栈,它仅由 cookie 拦截器组成
  • 声明“portletDefaultStack”作为您的默认拦截器堆栈

由于“portletDefaultStack” ”不包含你的“ekp-cookie-stack”,那么cookie拦截器将不会被调用。基本上,您配置一个堆栈,然后告诉 Struts2 使用不同的堆栈。

试试这个:

<interceptor-stack name="portletDefaultStackWithCookie">
    <interceptor-ref name="portletState"/>
    <interceptor-ref name="portletAware"/>
    <interceptor-ref name="cookie">
        <param name="cookiesName">my-filter-cookie</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack"/>
</interceptor-stack>

<default-interceptor-ref name="portletDefaultStackWithCookie" />

您可能还想在 CookieInterceptorintercept 方法中设置断点,以确保它被正确调用。

You are:

  • Defining an interceptor called "superInterceptor" (not sure where that fits in)
  • Defining an interceptor stack called "ekp-cookie-stack", which consists solely of the cookie interceptor
  • Declaring "portletDefaultStack" as your default interceptor stack

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:

<interceptor-stack name="portletDefaultStackWithCookie">
    <interceptor-ref name="portletState"/>
    <interceptor-ref name="portletAware"/>
    <interceptor-ref name="cookie">
        <param name="cookiesName">my-filter-cookie</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack"/>
</interceptor-stack>

<default-interceptor-ref name="portletDefaultStackWithCookie" />

You may also want to set a breakpoint in the CookieInterceptor's intercept method to make sure that it is being invoked properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文