項目網站: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。
----
完畢