项目网站:www.aikan66.com
游戏网站:www.aikan66.com
图片网站:www.aikan66.com
书籍网站:www.aikan66.com
学习网站:www.aikan66.com
Java网站:www.aikan66.com
iOS网站:www.aikan66.comhtml
----java
为Action对象配置输出执行时间的拦截器,查看执行Action所须要的时间。apache
----jsp
一、配置Struts2开发环境学习
二、建立类TestAction网站
package dog; import com.opensymphony.xwork2.ActionSupport; public class TestAction extends ActionSupport{ private static final long serialVersionUID=1L; public String execute() throws Exception{ //线程睡眠1s Thread.sleep(1000); return SUCCESS; } }
三、配置struts.xmlui
<?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.devMdoe" value="true"/> <!-- 声明常量 (在Struts2的配置文件修改后,自动加载)--> <constant name="struts.configuration.xml.reload" value="true"/> <!-- 声明包 --> <package name="myPackage" extends="struts-default"> <!-- 定义action --> <action name="testAction" class="dog.TestAction"> <!-- 配置拦截器 --> <interceptor-ref name="timer"/> <!-- 定义成功的映射页面 --> <result>success.jsp</result> </action> </package> </struts>
四、建立success.jspthis
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'success.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> this is timer? </body> </html>
修改index.jspspa
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <a href="testAction.action">定时器</a> </body> </html>
五、部署,访问:http://localhost:8080/jwrm153-Intercepter/
点击“定时器”
第一次访问TestAction时,须要进行一些初始化的操做,在之后的访问中就能够看到执行时间变成1000ms。
----
完毕