Question

I want to know this file is it correct, because I didn't understand interceptor very well.

struts.xml:

<struts>
    <interceptors>
 <interceptor-stack name="storeStack"> 
    <interceptor-ref name="defaultStack"/> 
    <interceptor-ref name="store"> 
        <param name="operationMode">STORE</param> 
    </interceptor-ref> 
</interceptor-stack>
            <interceptor-stack name="retrieveStack"> 
                <interceptor-ref name="defaultStack"/> 
                <interceptor-ref name="store">   
                </interceptor-ref> 
            </interceptor-stack>
        </interceptors>
        <action name="index">
            <result>/JSPs/eleve/view.jsp</result>
        </action>
        <action name="ajoutereleves" class="com.injaz.struts2.actions.NavigateAction" method="navigateToAjouterEleveJsp">
            <result name="ajoutereleves">/JSPs/eleve/addeleve.jsp</result>
        </action>
        <action name="listereleves" class="com.injaz.struts2.actions.NavigateAction" method="navigateToListerElevesJsp">
            <result name="listereleves">/JSPs/eleve/showseleves.jsp</result>
        </action>
        <action name="manageeleves" class="com.injaz.struts2.actions.NavigateAction" method="navigateToUpdateElevesJsp">
            <result name="manageeleves">/JSPs/eleve/manageeleves.jsp</result>
        </action>
         <action name="ajoutereleverecord" class="com.injaz.struts2.actions.AddEleveAction" method="execute">
                  
                <interceptor-ref name="defaultStack"/> 
                <interceptor-ref name="store"/>  
            <result name="success">/JSPs/eleve/addeleve.jsp</result>        
            <result name="error">/JSPs/eleve/addeleve.jsp</result>
        </action>
         <action name="updateeleve" class="com.injaz.struts2.actions.UpdateEleveAction" method="execute"> 
            <result type="json">
                <param name="contentType">text/html</param>
            </result>
        </action>
         <action name="getupdateeleve" class="com.injaz.struts2.actions.EditEleveAction" method="getEleveObject">
            <interceptor-ref name="storeStack" /> 
            <result name="success">/JSPs/eleve/editeleve.jsp</result>
            <result name="error">/JSPs/eleve/editeleve.jsp</result>
        </action>
        <action name="eleveTable" method="getEleveTable" 
                class="com.injaz.struts2.actions.EleveJsonTable">
            <result type="json">
                <param name="contentType">text/html</param>
            </result>
        </action>       
        <action name="validateEleve" class="com.injaz.struts2.validator.EleveValidator" method="validateEleveNom">
        <result type="json">
        <param name="contentType">text/html</param>
        </result>
        </action>   
    </package>
</struts>

I am using Struts 2.3.1 for more details.

Was it helpful?

Solution

No, your struts.xml is incorrect. Interceptors are invoked before the action execution. It's like a pipeline that serves the request. Each of them invoked one after another. When the last interceptor processed the action is executed. What interceptors to invoke configured in the action configuration or via annotations. For detail explanation of interceptors see docs.

The important thing is the order the interceptors are invoked on the stack. There's a defaultStack where the interceptors are collected and ordered appropriately. If you add a reference of the custom interceptor to the stack or action it should comply the order it placed.

The xml configuration file should comply the DTD.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top