1. 创建动态的Java Web项目
2. 加入lib包
3. 创建web.xml,在文件中声明StrutsPrepareAndExecuteFilter过滤器
4. 创建TestAction
package com.yuan;
import com.opensymphony.xwork2.ActionSupport;
public class TestAction extends ActionSupport{
private static final long serialVersionUID = 1L;
public String execute() throws Exception{
Thread.sleep(1000);
return SUCCESS;
}
}
5. 在struts.xml中配置TestAction对象,并将输出Action执行时间的拦截器timer应用到TestAction中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.configuration.xml.reload" value="true"/>
<package name="myPackage" extends="struts-default" >
<action name="TestAction" class="com.yuan.TestAction">
<interceptor-ref name="timer"/>
<result>success.jsp</result>
</action>
</package>
</struts>
6. 创建index.jsp和success.jsp
<body> <a href="TestAction.action">test</a> </body>
<body> success please observe the time </body>
7. 运行