我用的eclipse配置都弄了,也能输出就是不能输出时间?? 求教。
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 指定Strust配置文件的DTD信息 -->
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- 指定Struts2配置文件的根元素 -->
<struts>
<package name="default" namespace="/" extends="struts-default">
<!-- 注册拦截器 -->
<interceptors>
<interceptor name="mytimer" class="com.imooc.interceptor.TimerInterceptor"></interceptor>
</interceptors>
<action name="timer" class="com.imooc.action.TimerAction">
<result>/success.jsp</result>
<!-- 引用拦截器 -->
<interceptor-ref name="mytimer"></interceptor-ref>
</action>
</package>
</struts>
TimerAction.java
package com.imooc.action;
import com.opensymphony.xwork2.ActionSupport;
public class TimerAction extends ActionSupport {
@Override
public String execute() throws Exception {
for(int i=0; i<10000;i++){
System.out.println("陈京辉");
}
return SUCCESS;
}
}
TimerInterceptor.java
package com.imooc.interceptor;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/*
* 计算Action花费时间
*/
public class TimerInterceptor extends AbstractInterceptor {
@Override
public String intercept(ActionInvocation invocation) throws Exception {
//1.执行Action之前
long start = System.currentTimeMillis();
//2.执行下一个拦截器,如果已经是最后一个拦截器,则执行目标Action
String result = invocation.invoke();
//3.执行Action之后
long end = System.currentTimeMillis();
System.out.println("执行Action花费的时间:" + (end - start) + "ms");
return result;
}
}