Sandeep vashisth
Sandeep vashisth

Reputation: 1088

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

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

Upvotes: 1

Views: 509

Answers (2)

Sandeep vashisth
Sandeep vashisth

Reputation: 1088

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

Upvotes: 1

Boris the Spider
Boris the Spider

Reputation: 61138

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.

Upvotes: 1

Related Questions