1. Description
PreResultListener is a listener interface, which can be called back between physical views after the Action is completed and transferred to the system.
The Struts2 application can add the PreResultListener listener for the Action and interceptor, and add the PreResultListener listener through the addPreResultListener () method of ActionInvocation. Once the PreResultListener listener is added to the Action, the listener can call back the beforeResult () method of the listener before the application is transferred to the actual physical view. Once the interceptor is added with the PreREsultListener listener, the listener applies to all the actions intercepted by the interceptor.
2. Instance
| The code is as follows: |
Copy code |
Public class myAction extends Action { Public String execute () { ActionInvocation invocation = ActionContext. getContext (). getActionInvocation (); Invocation. addPreResultListener (new PreResultListener () { Public void beforeResult (ActionInvocation invacation, String resultCode) { // Method body write the listener business logic we need to process // The above parameter resultCode is the request sent by the foreground (that is, the logical name of the Action) } }); } } |