The following is a code snippet from a struts.xml file for Struts 2. If you see below, they are referencing “basicStack”, then referencing “prepare” and “servletConfig” in the next few lines. If you look at the definition of “basicStack” in struts-default, it looks like those two are already referenced as part of the “basicStack”. So wouldn’t referencing them after you have already referenced “basicStack” be redundant and not necessary? Thanks in advance.
<interceptor-ref name="basicStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">info</param>
</interceptor-ref>
<interceptor-ref name="servletConfig" />
<interceptor-ref name="staticParams"/>
<interceptor-ref name="prepare" />
<interceptor-ref name="chain"/>
<interceptor-ref name="tokenSession">
Having the interceptors in the stack twice means they will execute twice. This is not always redundant – for example, the paramsPrepareParamsStack has the params interceptor configured twice.
So you need to look at what the interceptors do. The servletConfig interceptor sets various action properties based off of what interfaces they implement. It is used for things like setting the request object. I can’t see a way in which having that interceptor run twice would be helpful, so I would wager a guess and say that it is in fact redundant.
The second interceptor in question, the prepare interceptor, triggers the prepare method of your action class to run. This could have valuable use being run when it is – for example, if your prepare method requires the request object in order to execute. If that is the case, it is possible that the first call to the prepare interceptor is redundant, and whoever defined this stack just didn’t want to enumerate the entire stack themselves.