struts2 hinzufügen Abfangjäger in struts.xml für alle action-Klasse

Ich habe das Struts framework 2 und ich habe eine Webanwendung erstellt, die eine Login-Seite. Ich habe drei verschiedene Action Klassen benannt Action1, Action2, Action3, und verschiedene Ansichten für die JSP-Seiten dargestellt sind, indem Sie einige business-Logik in der Action Klassen.

Nun, ich möchte, um zu überprüfen, ob ein Benutzer angemeldet hat, bevor die Action Klasse führt die Verarbeitung. Also, ich habe einen interceptor unten, funktioniert einwandfrei.

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;
}

Was will ich in der struts.xml ist anstelle der Zugabe ein interceptor für alle Aktionen, wie die, die unten

<interceptor-ref name="newStack"/>

Meine struts.xml Datei hat

<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>

Für jede Handlung, die ich haben will, einige definition, geschrieben in struts.xml läuft die Abfangjäger statt manuell hinzufügen

<interceptor-ref name="newStack"/> 

InformationsquelleAutor Java Beginner | 2013-06-05

Schreibe einen Kommentar