Struts 2 interface after action

Is there any struts2 interface after doing the action

Prepared for before performing such an action, how do we have anything after performing the action?

+4
source share
4 answers

If you want to execute a method before and after the action, you can use the following annotations, but you need to configure AnnotationWorkflowInterceptor

@Front

@After

+5
source

No no. (And I'm not sure why you want such a thing.)

The simplest options are:

  • Create your own Prep Interceptor to do this.
  • Create a base action class that subclasses the actual action.
  • Use AOP, for example, using Spring or AspectJ.
+1
source

I'm not sure what your scenario is, but I think it matters what you are looking for: Run and wait for the interceptor

0
source

There is a PreResultListener interface. The implementation of this from the action is not the most beautiful.

An example of using this interface for your purpose may be to create an abstract support class, for example:

public abstract class PreResultSupport extends ActionSupport implements PreResultListener { protected abstract String doExecute(); @Override public String execute() { ActionContext.getContext().getActionInvocation().addPreResultListener(this); return doExecute(); } } 

Then, for the actions you want to perform "after preparation", you can extend this support class:

 public class ExampleAction extends PreResultSupport { private String instanceField; @Override protected String doExecute() { //your action code here return SUCCESS; } @Override public void beforeResult(ActionInvocation invocation, String resultCode) { //your "post-prepare" or "view-prepare" code here //this is threadsafe as well, so you can still reference class fields: this.instanceField = "blahblahblah"; } } 
0
source

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


All Articles