Struts2学习笔记四:struts.xml
来源:互联网 发布:网络机房空调 编辑:程序博客网 时间:2024/06/05 00:07
struts.xml是Struts2框架的核心配置文件。该文件主要负责管理Struts2框架中的Action。如果有多个类似的配置文件,可以在struts.xml中使用<include>标签将其它配置文件包含起来,格式为:<include file="struts1.xml" />。struts.xml放在src目录下即可。应用程序会自动加载一个名为 struts-default.xml文件,这个文件就加载了许多定义好的类和插件等配置。
struts.xml的配置元素如下:
- 配置Bean
- 作用
- 创建Bean实例,并作为框架的内部对象使用
- 对Bean包含的静态方法进行注入
- 属性
- class(必选):Bean的类名
- type(可选):Bean实现的接口
- name(可选):Bean实例的名字,必须唯一
- scope(可选):Bean实例的作用域,值必须是default、singleton、request、session或thread其中之一
- static(可选):指定Bean是否使用静态方法注入。当指定type属性时,该属性值不能为true。
- optional(可选):是否为一个可选的Bean
- 格式:<bean class="" name="" optional="" scope="" static="" />
- 作用
- 配置常量
- 常量配置方法
- 在struts.properties文件中配置常量
- 在struts.xml文件中配置常量,struts2推荐使用此方式
- 在web.xml中配置常量
- 常量的读取顺序
- struts-default.xml
- struts-plugin.xml
- struts.xml
- struts.properties
- web.xml
- 如果在多个文件中配置同一个常量,则后一个配置文件中的常量会覆盖前一个配置文件中的同名常量的值
- 常量配置方法
- 配置包
- 属性
- name(必选):包的名字
- extends(可选):指定该包继承自哪个包。如果该包继承了其他包,就可以继承包中的Action、拦截器等
- namespace(可选):包的命名空间
- 命名空间名必须以斜线(/)开头
- Struts2不会对命名空间分层查找
- abstract(可选):指定当前包是否为一个抽象包。抽象包不能包含Action
- externalReferenceResolver(可选):暂未使用过
- 属性
- 配置拦截器
<!-- 配置拦截器 --><interceptors><!-- 拦截器 --><interceptor name="" class="" /><!-- 拦截器栈,即多个不同拦截器的集合 --><interceptor-stack name=""><interceptor-ref name="" /><interceptor-ref name="" /></interceptor-stack></interceptors>
0 0
- Struts2学习笔记四:struts.xml
- Struts2学习总结(四):struts.xml的配置
- Struts2学习笔记(四)——Struts标签相关
- struts2 学习笔记之 struts.xml 配置解析
- J2EE Struts2 学习笔记003 ---- struts.xml 解析
- Struts2学习笔记(二)数据驱动与struts.xml配置
- Struts2学习笔记(三):struts.xml文件详解
- struts2 struts-default.xml 学习
- struts2学习笔记(四)基于xml的框架校验
- Struts2学习笔记四
- Struts2学习笔记(四)
- struts2学习笔记四
- Struts2笔记二之struts.xml
- Struts-config.xml学习笔记
- Struts-config.xml学习笔记
- 【转载】Struts2学习总结----struts.xml 配置
- struts2学习(二)struts.xml配置
- struts2 笔记struts.devMode struts.configuration.xml.reload
- 用Pymel里的with来些UI
- 实现Java程序跨平台运行十二个注意事项
- AX2009常用例子
- phpcms整站代码分析
- 如何在CentOS 5/6上安装EPEL源
- Struts2学习笔记四:struts.xml
- java从Eclipse的Console中读取数据(尤其汉字)遇到的问题
- 【PMP考试难点辨析】质量管理三大过程剖析及易错题总结(丁仿)
- 2000-使用Hive的正则解析器RegexSerDe分析Nginx日志
- javascript定义对象写法
- ArcGIS10.3_解决属性表中文乱码问题
- 获取对象的几种方式与构造函数Constructor的调用
- Scrapy spiders介绍
- postgresql 存储过程简单使用