I use struts2 to build a login platform. I use an Interceptor extends MethodFilterInterceptor. In the method doIntercept, I use "actionInvocation.invoke()" instead of "return actionInvocation.invoke()". But it also run.
struts-2.5.18
public class loginInterceptor extends MethodFilterInterceptor {
@Override
protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
if (ServletActionContext.getRequest().getSession().getAttribute("user") != null){
actionInvocation.invoke();
}
return null;
}
}
I think because the method return null, it should not jump to the view. However, it does.
Please see the "Writing Interceptors" docs.
The important part:
I.e., if you call
invoke, the interceptors and action will be executed as normal.To short-circuit normal processing do not call
invoke, instead return a result suitable to your purposes, e.g., a login page's global result.