`

struts2-自定义拦截器

阅读更多
用来验证。。。等等

package com.hugui.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;


public class MyInterceptor implements Interceptor{

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public void init() {
		// TODO Auto-generated method stub
		
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		long start = System.currentTimeMillis();
		String r = invocation.invoke();
		long end = System.currentTimeMillis();
		System.out.println("action time = " + (end - start));
		return r;
	}

}



<?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>


	<constant name="struts.devMode" value="true"></constant>
	<package name="test" namespace="/" extends="struts-default">
		<interceptors>
			<interceptor name="my" class="com.hugui.interceptor.MyInterceptor"></interceptor>
		</interceptors>


		<action name="test" class="com.hugui.action.TestAction">
			<result>/test.jsp</result>
<!--就这个写在dedfaultStack前-->
			<interceptor-ref name="my"></interceptor-ref>
			<interceptor-ref name="defaultStack"></interceptor-ref>
		</action>

	</package>


</struts>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics