how to calling a custom interceptor before index.jsp(welcome) page loaded in struts 2 application

StackOverflow https://stackoverflow.com/questions/14921327

  •  10-03-2022
  •  | 
  •  

Question

there is any way in Struts 2 that works like a ServletContextListener? The reason why I'm trying to do this is I do have some values that would be fetched from the DB and I want these values to available in my application home page when ever home page is laoded

Was it helpful?

Solution 2

i solved my problem create index file in webContent folder and set index and create a action in struts.xml with name index.

OTHER TIPS

You need to add an PreResultListener to your action:

public class MyInterceptor extends AbstractInterceptor {
  private static final long serialVersionUID = 5065298925572763728L;
    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
      // Register a PreResultListener and implement the beforeReslut method
      invocation.addPreResultListener(new PreResultListener() {
        @Override
        public void beforeResult(ActionInvocation invocation, String resultCode) {
          //dostuff
        }
      });

      // Invocation Continue
      return invocation.invoke();
    }
  }
}

Taken from here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top