<i id='Glmxl'><tr id='Glmxl'><dt id='Glmxl'><q id='Glmxl'><span id='Glmxl'><b id='Glmxl'><form id='Glmxl'><ins id='Glmxl'></ins><ul id='Glmxl'></ul><sub id='Glmxl'></sub></form><legend id='Glmxl'></legend><bdo id='Glmxl'><pre id='Glmxl'><center id='Glmxl'></center></pre></bdo></b><th id='Glmxl'></th></span></q></dt></tr></i><div id='Glmxl'><tfoot id='Glmxl'></tfoot><dl id='Glmxl'><fieldset id='Glmxl'></fieldset></dl></div>
    <bdo id='Glmxl'></bdo><ul id='Glmxl'></ul>
  • <small id='Glmxl'></small><noframes id='Glmxl'>

    <tfoot id='Glmxl'></tfoot>

    1. <legend id='Glmxl'><style id='Glmxl'><dir id='Glmxl'><q id='Glmxl'></q></dir></style></legend>

        在 struts.xml 中为所有 Action 类添加拦截器

        Adding interceptors in struts.xml for all Action classes(在 struts.xml 中为所有 Action 类添加拦截器)
      1. <small id='6jHxv'></small><noframes id='6jHxv'>

          <tbody id='6jHxv'></tbody>

      2. <i id='6jHxv'><tr id='6jHxv'><dt id='6jHxv'><q id='6jHxv'><span id='6jHxv'><b id='6jHxv'><form id='6jHxv'><ins id='6jHxv'></ins><ul id='6jHxv'></ul><sub id='6jHxv'></sub></form><legend id='6jHxv'></legend><bdo id='6jHxv'><pre id='6jHxv'><center id='6jHxv'></center></pre></bdo></b><th id='6jHxv'></th></span></q></dt></tr></i><div id='6jHxv'><tfoot id='6jHxv'></tfoot><dl id='6jHxv'><fieldset id='6jHxv'></fieldset></dl></div>
        • <bdo id='6jHxv'></bdo><ul id='6jHxv'></ul>
          <legend id='6jHxv'><style id='6jHxv'><dir id='6jHxv'><q id='6jHxv'></q></dir></style></legend>

                  <tfoot id='6jHxv'></tfoot>
                1. 本文介绍了在 struts.xml 中为所有 Action 类添加拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我使用了 Struts 2 框架并创建了一个具有登录页面的 Web 应用程序.我有三个不同的 Action 类,分别命名为 Action1Action2Action3,以及用于呈现的 JSP 页面的不同视图通过在 Action 类中运行一些业务逻辑.

                  I've used the Struts 2 framework and I have created a web application which has a Login Page. I have three different Action classes named Action1, Action2, Action3, and different views for JSP pages which are rendered by running some business logic in the Action classes.

                  现在,我想在 Action 类执行处理之前检查用户是否已经登录.所以,

                  Now, I want to check whether a user has logged in before the Action class carries out processing. So,

                  我在下面创建了一个可以正常工作的拦截器:

                  public String intercept(ActionInvocation invocation) throws Exception 
                  {
                      HttpServletRequest  request  = ServletActionContext.getRequest();
                      HttpServletResponse response = ServletActionContext.getResponse();
                      HttpSession         session  = request.getSession();
                      
                      if(session.isNew())
                      {
                          response.sendRedirect("Login.action");
                      }
                      
                      System.out.println("Interceptor Fired");
                      String result = invocation.invoke();
                      return result;
                  }
                  

                  我想在 struts.xml 中做的不是为下面的所有操作添加一个拦截器

                  What I want to be in struts.xml is instead of adding an interceptor for all the actions like the one below

                  <interceptor-ref name="newStack"/>
                  

                  我的 struts.xml 文件有:

                  My struts.xml file has:

                  <package name="default" extends="struts-default">       
                     <interceptors>   
                      <interceptor name="printMsgInterceptor" class="LoginInterceptor"></interceptor>
                           <interceptor-stack name="newStack">
                          <interceptor-ref name="printMsgInterceptor"/>
                          <interceptor-ref name="defaultStack" />
                           </interceptor-stack>
                       </interceptors>
                  
                      <action name="actone" class="Action1">
                        <result name="success">/success.jsp</result>
                        <interceptor-ref name="newStack"/>
                      </action>
                          <action name="acttwo" class="Action2">
                        <result name="success">/success.jsp</result>
                        <interceptor-ref name="newStack"/>
                      </action>
                           <action name="actthree" class="Action3">
                        <result name="success">/success.jsp</result>
                        <interceptor-ref name="newStack"/>
                      </action>
                      </package>
                  

                  对于每个动作,我都希望在 struts.xml 中编写一些定义,它运行拦截器而不是手动添加

                  For every action I want to have some definition written in struts.xml which runs the interceptor rather than manually adding

                  <interceptor-ref name="newStack"/> 
                  

                  推荐答案

                  <interceptor name="test" class="Full path for LoginInterceptor" />
                  
                      <interceptor-stack name="testStack">  
                           <interceptor-ref name="test"/>
                           <interceptor-ref name="defaultStack"/> //here you are including default stack
                      </interceptor-stack> 
                  
                  </interceptors>  
                  <default-interceptor-ref name="testStack"></default-interceptor-ref>
                  

                  现在 testStack 将为每个请求执行

                  Now testStack will execute for every request

                  这篇关于在 struts.xml 中为所有 Action 类添加拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                    • <bdo id='y0dnP'></bdo><ul id='y0dnP'></ul>

                        <tbody id='y0dnP'></tbody>

                      <small id='y0dnP'></small><noframes id='y0dnP'>

                      • <legend id='y0dnP'><style id='y0dnP'><dir id='y0dnP'><q id='y0dnP'></q></dir></style></legend>
                        <tfoot id='y0dnP'></tfoot>

                            <i id='y0dnP'><tr id='y0dnP'><dt id='y0dnP'><q id='y0dnP'><span id='y0dnP'><b id='y0dnP'><form id='y0dnP'><ins id='y0dnP'></ins><ul id='y0dnP'></ul><sub id='y0dnP'></sub></form><legend id='y0dnP'></legend><bdo id='y0dnP'><pre id='y0dnP'><center id='y0dnP'></center></pre></bdo></b><th id='y0dnP'></th></span></q></dt></tr></i><div id='y0dnP'><tfoot id='y0dnP'></tfoot><dl id='y0dnP'><fieldset id='y0dnP'></fieldset></dl></div>