I am working on Struts 2. During the implementation of an Interceptor, I came across to a question:
is it possible to stop the execution of an Interceptor all together via configuration or any other way ?
I am working on Struts 2. During the implementation of an Interceptor, I came across to a question:
is it possible to stop the execution of an Interceptor all together via configuration or any other way ?
There are many ways to decide when a Struts2 Action must run through an Interceptor or not... the easiest are most likely:
Programmatically - Interceptor Configuration
Define the same action multiple times, each one running with a different interceptor stacks (both defined globally at package level or, like in the following example, in the action configuration itself), one containing your interceptor, the other without it:
Programmatically - Method Filtering
Extend this abstract interceptor in your custom interceptor, and define the methods that will filter the interceptor execution in the configuration . In the example, every action method named
foo()
, orbar()
, or starting withwithoutCustom
likewithoutCustomMethod()
will avoid running the interceptor, all the other methods instead will run it :Dynamically - From within the Interceptor
Do it in the Interceptor logic, basing on
a request parameter:
a session parameter:
an Interface extended by your Action:
Etcetera...