java - setSession() 没有被调用?

标签 java session configuration struts2 struts2-interceptors

在实现 SessionAware 的操作类中,未调用其 setSession()。 我直接在 execute() 上收到回调。

以下是一些相关详细信息:

Struts.xml

<package name="profile" extends="struts-default" namespace="/profile">
    <result-types>
        <result-type name="dispatcher"
            class="org.apache.struts2.dispatcher.ServletDispatcherResult"
            default="true" />
        <result-type name="tiles"
            class="org.apache.struts2.views.tiles.TilesResult"></result-type>
    </result-types>
    <interceptors>
        <interceptor name="authenticationinterceptor"
            class="interceptors.common.AuthenticationInterceptor"></interceptor>
        <interceptor-stack name="secureInterceptor">
            <interceptor-ref name="authenticationinterceptor"></interceptor-ref>
        </interceptor-stack>
    </interceptors>

    <action name="staff" class="actions.profile.StaffProfileAction">
        <interceptor-ref name="secureInterceptor"></interceptor-ref>
        <result name="success" type="tiles">/profilestaff.tiles</result>
    </action>

</package>

Action 类

public class StaffProfileAction extends ActionSupport implements SessionAware {
    SessionMap<String, Object> sessionmap;

    public String execute() throws Exception {

    }

    @Override
    public void setSession(Map<String, Object> session) {
        logger.info("StaffProfileAction->setSession");
        sessionmap = (SessionMap<String, Object>) session;

    }
}

我没有使用默认堆栈中的任何拦截器。我是否需要添加任何拦截器才能接收 setSession() 上的回调。请指出我的错误。

最佳答案

是的,您需要servletConfig拦截器。

An interceptor which sets action properties based on the interfaces an action implements.

因为您实现了 SessionAware,所以拦截器应该位于堆栈上,以允许使用 servlet session 功能。

关于java - setSession() 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23388436/

相关文章:

java - JPA更新表结构-数据发生了什么

Java 17 : Maven doesn't give much information about the error that happened, 为什么?

java - append 到 HDFS 中的现有文件时出现异常

php - Codeigniter:用户 session 不断过期

mysql - 如何检查 MySQL 触发器中 OLD.* 到 NEW.* 列中每个列的差异?

scala - 如何在 sbt 测试中覆盖 application.conf 中的日志级别?

configuration - $cfg ['Servers' ][$i] ['users' ] ... 不行

java : stop safety a thread; not using while and boolean flag

ruby-on-rails - Rails ActiveRecord存储和新 session

web-services - com.ctc.wstx.exc.WstxParsingException : Text size limit