Struts2-配置详解

<struts>
	<!-- 配置struts运行参数(常量) -->
	<!-- 开发模式,在开发阶段设置为true可以输出更多的日志 -->
	<constant name="struts.devMode" value="true"></constant>
	<!-- 主题,一般不使用struts提供模板设置为simple -->
	<constant name="struts.ui.theme" value="simple"></constant>
	<!-- 扩展名,struts处理请求的扩展名,要配置多个,中间以半角逗号分隔 -->
	<constant name="struts.action.extension" value="action"></constant>

	<!-- 配置包,包中配置action
	name:包名称,每个package名称不允许同名
	namespace:命名空间,是url的一部分,如果要请求customer包下的action,url就是:http://localhost:8080/工程路径/customer。namespace可以不配置,值是空字符串,就是默认命名空间即空字符号
	extends:继承,包与包之间可以继承,这里让它继承struts-default.xml中包struts-default,可以使用父包中的对象了
	 -->
	<package name="customer" namespace="/customer" extends="struts-default">
		<!-- 默认执行action名称
		当请求当前的package,如果请求的action名称在package找不到,执行默认名称
		 -->
		<default-action-ref name="list"></default-action-ref>	
		<!-- 全局的公用的result -->
		<global-results>
			<result name="success" type="dispatcher">
				/jsp/success.jsp
			</result>
			<result name="error" type="dispatcher">
				/jsp/error.jsp
			</result>
		</global-results>
			
		<!-- 配置action
		name="add":指定action的名称,名称是请求url的一部分,将要请求此action,url是:http://localhost:8080/工程路径/customer/add.action
		class:action的类路径,前端控制器通过struts.xml根据url找action,找到action的类路径,创建action实例
		method:请求action执行的方法,可以不配置,如果不配置,当请求add.action时执行CustomerAction的execute方法
		 -->
		<action name="add" class="cn.chyson.wap.action.CustomerAction" method="add">
			<!--配置页面
			name:即action方法返回的逻辑视图名
			type="dispatcher":转发到页面,在result中配置jsp路径
			type="redirect":重定向,如果是重定向,配置url
			 -->
			<result name="success" type="dispatcher">
				/jsp/customer/add.jsp
			</result>
		</action>
	</package>
</struts>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值