Struts 2: exception of method from check only from defaultStack interceptor

I want to be able to disable form validation for a single action in Struts 2, but the rest of the interceptor stack may still work.

I have an interceptor that checks if a user is logged in, which I always want to perform, but for some actions (for example, entering information) I do not want the validate action to be called.

I tried to do something like the following:

 <interceptors> <interceptor name="bankingAuthenticator" class="csc309.a4.banking.BankUserAuthenticator"/> <interceptor-stack name="secureBanking"> <interceptor-ref name="bankingAuthenticator"/> <interceptor-ref name="defaultStack"/> </interceptor-stack> </interceptors> <default-interceptor-ref name="secureBanking"/> <action name="Deposit!*" method="{1}" class="csc309.a4.banking.Deposit"> <result name="success">/banking/Deposit.jsp</result> <interceptor-ref name="defaultStack"> <param name="workflow.excludeMethods">choose</param> </interceptor-ref> </action> 

But it misses both the bankingAuthenticator interceptor and the check.

+4
source share
1 answer

I realized this - the solution looks like this:

 <action name="Deposit!*" method="{1}" class="csc309.a4.banking.Deposit"> <result name="success">/banking/Deposit.jsp</result> <interceptor-ref name="secureBanking"> <param name="workflow.excludeMethods">choose</param> </interceptor-ref> </action> 

Interceptor parameters can be limited to specific interceptors by adding an interceptor name to the parameter name. In this case, only the workflow interceptor excludes the choose method; other interceptors will still fire for the choose action method.

+5
source

Source: https://habr.com/ru/post/1381050/


All Articles