Struts2-配置详解

来源:互联网 发布:弱水三千歌词知乎 编辑:程序博客网 时间:2024/06/12 00:16
<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><!-- 配置包,包中配置actionname:包名称,每个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><!-- 配置actionname="add":指定action的名称,名称是请求url的一部分,将要请求此action,url是:http://localhost:8080/工程路径/customer/add.actionclass: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>

原创粉丝点击