繁体   English   中英

拦截器破坏方法

[英]Interceptor destroy method

我在struts2中创建了一个Authentication Interceptor
我必须检查何时拦截器方法被调用。
所以我已经在控制台上打印了方法名称。

这是我的代码

public class AuthenticationInterceptor implements Interceptor {

@Override
public void destroy() {
    System.out.println("AuthenticationInterceptor destroy");

}

@Override
public void init() {
     System.out.println("AuthenticationInterceptor init");

}

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception    {
    System.out.println("AuthenticationInterceptor intercept");
    return actionInvocation.invoke();
   }
} 

这是我在struts.xml中的软件包。

<package name="portfolioSecure" namespace="/secure" extends="portfolio">
<interceptors>
<interceptor name="authenticationInterceptor" class="ask.portfolio.utility.AuthenticationInterceptor"></interceptor>
<interceptor-stack name="secureStack">
<interceptor-ref name="authenticationInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>

</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack"></default-interceptor-ref>
    <action name="login" class="ask.portfolio.actions.Login">
        <result name="success">/loginSuccess.jsp</result>
        <result name="error">/welcome.jsp</result>
    </action>
</package>

当我的应用程序启动时,在控制台上打印AuthenticationInterceptor init
且同样会打印AuthenticationInterceptor拦截器。但是即使我停止服务器,我也想知道何时调用拦截器destroy方法 ,并且拦截器中的后处理与destroy method()有关,但不会打印AuthenticationInterceptor destroy

当容器或应用程序停止或未部署时,destroy方法仅调用一次。 它调用来让拦截器清除其已分配的所有资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM