为Action对象配置输出执行时间的拦截器对象,以查看执行Action所需的时间

本文详细介绍了如何使用Java语言创建动态Web项目,并通过加入lib包、配置StrutsPrepareAndExecuteFilter过滤器、实现TestAction类、在struts.xml中配置拦截器及创建相应jsp页面,完成Struts框架的集成。通过运行步骤,可以验证Struts框架在项目中的正确应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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. 运行





 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值