您的位置首页百科问答

拦截器会拦截servlet吗

拦截器会拦截servlet吗

的有关信息介绍如下:

拦截器会拦截servlet吗

你好,这个是肯定的呀!下面是截拦的方法!abstractInterceptor这个是xwork里面的包才有的类,就是你要在struts里面也是要用它。import java.util.Map;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.ValidationAware;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class AuthorizationInterceptor extends AbstractInterceptor {private static final String USER_KEY = "user";public String intercept(ActionInvocation invocation) throws Exception {Map session = invocation.getInvocationContext().getSession();if(session.get(USER_KEY) == null) {addActionError(invocation, "You must be authenticated to access this page");return Action.ERROR;}return invocation.invoke();}private void addActionError(ActionInvocation invocation, String message) {Object action = invocation.getAction();if(action instanceof ValidationAware) {((ValidationAware) action).addActionError(message);}}}