1

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

Sandeep vashisth
  • 1,040
  • 7
  • 20
  • 40

2 Answers2

1

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.

Boris the Spider
  • 59,842
  • 6
  • 106
  • 166
  • No this is not what i want. my question is how to call an interceptor or action on application initialize then a view display according to result returned from the action. simply i say my welcome page come through a action. – Sandeep vashisth Feb 18 '13 at 16:55
1

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

Sandeep vashisth
  • 1,040
  • 7
  • 20
  • 40