[Struts2官方指南的个人学习和翻译] Struts2的配置元素-管理元素
2015-04-18 13:31
405 查看
-BeanStrus2在内部使用一个独自的依赖注入容器,初始化时载入了框架的关键对象,使整个框架的任意模块可以被替换、继承、删除通过一个统一的标准方式。特别对于插件,可以利用这个方式来拓展框架,提供对第三方类库的支持。
Bean元素必须要有class属性来指定其对应的Java类,才能进行对对象的创建和操作。
Bean Example (struts.xml)
-ConstantConstant提供一个简单的方式用于修改Struts2框架和其插件的参数,其中有两个重要的功能:1.修改一些参数,如最大上传文件的大小,使用使用“DevMode”等等。2.当多个bean实现了同一接口,应该进行选择使用哪一个。Constant可以被定义在多个文件中,将按照如下的顺序进行搜索,后面的文件中的Constant会覆盖之前的。1.struts-default.xml2.struts-plugin.xml3.struts.xml4.struts.properties5.web.xml在XML中的定义
如在web.xml中,FilterDispatcher的参数都用constant来定义。
Constant Example (struts.xml)
Constant Example (struts.properties)
Constant Example (web.xml)
-Packagepackage将actions, results, result types, interceptors,和 interceptor-stacks 组成一个配置单元,并且类似于一个对象可以被继承和重载。
Package Example (struts.xml)
Multi package Example (struts.xml)
用于对action的划分,解决action名字的冲突问题,默认存在于default中。
当请求
Attribute | Required | Description |
---|---|---|
class | yes | the name of the bean class (对应的Java类的名字) |
type | no | the primary Java interface this class implements (该类实现了的主要接口) |
name | no | the unique name of this bean; must be unique among other beans that specify the same type (该Bean的名字可以用来区别于其他Bean) |
scope | no | the scope of the bean; must be either default, singleton, request, session, thread (该bean的作用范围) |
static | no | whether to inject static methods or not; shouldn't be truewhen the typeis specified(是否注入静态方法,当type被指定时不能选择true) |
optional | no | whether the bean is optional or not (该bean是否为可选的) |
Sample usage
Bean Example (struts.xml)Attribute | Required | Description |
---|---|---|
name | yes | the name of the constant |
value | yes | the value of the constant |
Sample usage
Constant Example (struts.xml)Attribute | Required | Description |
---|---|---|
name | yes | key to for other packages to reference (用于对一个package的唯一标识) |
extends | no | inherits package behavior of the package it extends (继承) |
namespace | no | see Namespace Configuration (命名空间) |
abstract | no | declares package to be abstract (no action configurations required in package) |
Simple usage
Package Example (struts.xml)
Inherit from more than one package
Multi package Example (struts.xml)
-Namespace
用于对action的划分,解决action名字的冲突问题,默认存在于default中。
Namespace Example
/barspace/bar.action ,先在barspace中寻找bar,若找不到则回退到default寻找,在上例中,barspace中存在bar,将跳转至 bar2.jsp。
当请求 /barspace/foo.action, 在上例中,barspace中不存在foo,则回退到default中寻找,所以将跳转至greeting.jsp。当请求/
moo.action,会先在/空间中寻找,上例中/中存在moo,则将会跳转至moo.jsp当请求 /foo.action,先在/空间中寻找,上例中/中不存在foo,回退至default中寻找,最后结果为greeting.jsp* namaspace和路径不同,没有层次划分,例如请求
/barspace/myspace.bar.action,在上例不存在该namespace,将会回退至default中寻找而不是barspace中。
相关文章推荐
- [Struts2官方指南的个人学习和翻译] Struts2的配置元素-请求处理元素
- [Struts2官方指南的个人学习和翻译] Struts2的配置文件
- [Struts2官方指南的个人学习和翻译] Struts2自带例子MailReader的学习
- [Struts2官方指南的个人学习和翻译] Struts2自带例子MailReader的学习
- Nginx 官方文档翻译 - nginx的配置文件管理
- Log4j2官方文档翻译、学习笔记之一——log4j2基础配置及功能概述
- 好好学习:个人知识管理精进指南
- Apple Watch 人机交互指南 界面元素 ----- Menus (官方文档翻译) (产品设计层面)
- Apple Watch 人机交互指南 界面元素 ---- Menu Icons (官方文档翻译)(UI设计层面)
- 读《好好学习:个人知识管理精进指南》
- Struts2学习:配置篇之管理层配置元素(一)
- struts2学习:配置篇值请求处理元素
- Sencha Touch 2 官方文档翻译之 Controllers(控制器学习指南)
- Sencha Touch 2 官方文档翻译之 Controllers(控制器学习指南)
- Sencha Touch 2 官方文档翻译之 Controllers(控制器学习指南)
- struts2学习:配置篇值请求处理元素
- JAVA_WEB Struts2学习:使用验证框架进行校验JSP页面元素 反编译工具的配置 Strtuts2 国际化学习
- Sencha Touch 2 官方文档翻译之 Controllers(控制器学习指南)
- GLFW v2.5 安装配置官方指南 及 下载链接
- android 官方文档人机交互指南在线翻译