struts2 拦截器

Stucts2 拦截器

public class InterceptorDemo1 extends AbstractInterceptor{

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		System.out.println("拦截前");
		String result = invocation.invoke();
		
		System.out.println("拦截 后");
		return result;
	}

}

  

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<package name="main" extends="struts-default">
		 <interceptors>
		<interceptor name="interceptorTest1" class="InterceptorDemo1" ></interceptor>
		<interceptor name="interceptorTest2" class="InterceptorDemo2" ></interceptor>
		<interceptor name="loginCheckInterceptor" class="LoginCheckInterceptor"></interceptor>
	   </interceptors> 
		<action name="MyAction" class="MyAction">
		<interceptor-ref name="interceptorTest1"></interceptor-ref>
			<interceptor-ref name="interceptorTest2"></interceptor-ref> 
			<result name="success">/index.jsp</result>
		</action>
		<action name="login" class="CustomerAction" method="login">
            <result>/login.jsp</result>
        </action>
		
	</package>
	
</struts>   

  

原文地址:https://www.cnblogs.com/linlf03/p/5156969.html