Strut2默认拦截器结果页面

发布于 2024-12-20 12:50:01 字数 1280 浏览 7 评论 0原文

在 struts2 中,我在 struts.xml 页面中有一个默认拦截器和许多操作。

我的 struts.xml 是这样的

<struts>
   <package>
       <interceptors>
         <interceptor-ref name="" class="" >
           <interceptor-stack name=""  >
               <interceptor-ref name="" />
               <interceptor-ref name="" />
            </interceptor-stack>
         </interceptor-ref>
       </interceptors>



       <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

        <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

        <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

   </package>
</struts>

在默认拦截器中我检查了会话。但是,如果未设置会话,我需要将页面重定向到登录页面,因此它应该适用于所有操作?我如何实现这个。我是否需要在所有操作中调用拦截器,或者如果我使用默认拦截器,如何在所有操作中设置重定向页面?

In struts2 i have one default interceptor and lot of actions in the struts.xml page.

My struts.xml is like this

<struts>
   <package>
       <interceptors>
         <interceptor-ref name="" class="" >
           <interceptor-stack name=""  >
               <interceptor-ref name="" />
               <interceptor-ref name="" />
            </interceptor-stack>
         </interceptor-ref>
       </interceptors>



       <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

        <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

        <action name="" class="package.class" method= "method"   >
         <result name="success">jsp page</result>
         <result name="success">jsp page</result>
       </action>

   </package>
</struts>

In the default interceptor i have check the session. But if session is not set i need to redirect the page to login page, hence it should be work in all actions?. How do i implement this. Do i need to call the interceptor in all action or if i use default interceptor how can i set the redirect page in all actions?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

仅此而已 2024-12-27 12:50:01

为此,您可以创建自己的拦截器来检查会话是否已设置。如果未设置,它会将您的请求重定向到登录页面。然后您可以将此拦截器添加到您想要的默认拦截器堆栈中。而且不需要每次都调用拦截器,struts2框架会在每个动作之前和之后自动调用拦截器。

您可以从此处查看如何制作您的自己的拦截器。

For this purpose you can make your own interceptor that will check if session is set or not. If it is not set it will redirect your request to login page. And then you can add this interceptor to the default interceptor stack where ever you want. And you don't need to call the interceptor each time, the struts2 framework will automatically call the interceptor before and after every action.

You can check from here how to make your own interceptor.

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