一个好老好老的老程序员了。
全部博文(915)
分类:
2011-09-28 22:31:54
一。 核心文件struts.xml 的配置
1。 bean的配置
主要就是名字的一个引用
...
The bean element has one required attribute, class, which specifies the class to be created or manipulated. A bean can either be created by the framework's container and injected into internal framework objects, or have values injected to its static methods The first use, object injection, is generally accompanied by the type attribute, which tells the container which interface this object implements. The second use, value injection, is good for allowing objects not created by the container to receive framework constants. Objects using value inject must define the the static attribute.Attribute Required Description class yes the name of the bean class type no the primary interface this class implements name no the unique name of this bean; must be unique among other beans that specify the same type scope no the scope of the bean; must be either default, singleton, request, session, thread static no whether to inject static methods or not; shouldn't be true when the type is specified optional no whether the bean is optional or not 3 Packages的配置简单就包的配置 是配置的一个逻辑规划Attribute Required Description name yes key to for other packages to reference 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) Sample usage Package Example (struts.xml)
{1}
execute
2 Constant 的配置。主要是对struts2 应用项目的一个全局配置,配合web。xml里配置Constants provide a simple way to customize a Struts application by defining key settings that modify framework and plugin behavior. There are two key roles for constants. First, they are used to override settings like the maximum file upload size or whether the Struts framework should be in "devMode" or not, and so on. Second, they specify which Bean implementation, among multiple implementations of a given type, should be chosen. Constants can be declared in multiple files. By default, constants are searched for in the following order, allowing for subsequent files to override previous ones:In the various XML variants, the constant element has two required attributes: name and value. Attribute Required Description name yes the name of the constant value yes the value of the constant In the struts.properties file, each entry is treated as a constant.In the web.xml file, any FilterDispatcher initialization parameters are loaded as constants.Sample usage Constant Example (struts.xml)
...
Constant Example (struts.properties)
struts.devMode = true
Constant Example (web.xml)
xmlns:xsi=""
xsi:schemaLocation=" ">
...
4.Namespace 的配置就是命名空间的配置 说白了就是你访问action 的前置url 有个默认空间 当你制定的空间找不到 就转到default里
5 include的配置
你可以将配置分割成多个
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"">
6 interceptors的配置
对拦截类的配置 还有堆栈 堆栈里有对个拦截 就是这个意思
7 Action 的配置 这个比较关键 也比较常用。与struts 1 的不同就是 这个action 把原来的action和form 都包含了
(1) action mapping 就是action类的对应名字
(2) Action Methods
默认是execute的方法,可以通过method参数访问多个action的方法,即 action可以有多个方法 可以扩展
即时访问这个类的delete方法
Wildcard Method
即时访问deleteCrud 访问deleteCrud 方法
即时访问eCrud 访问eCrud 方法
如此对应
(3) action default
(4) action wilddefault
(5 ) 扩展映射
class="org.apache.struts.webapp.example.Edit{1}Action">
path="/mainMenu.jsp"/>
Wildcard patterns can contain one or more of the following special tokens:
* Matches zero or more characters excluding the slash ('/') character. ** Matches zero or more characters including the slash ('/') character. \character The backslash character is used as an escape sequence. Thus '\*'matches the character asterisk ('*'), and '\\'matches the character backslash ('\').
8 Result 的配合 就是返回也的配置 与struts1是一一致的
struts2一些固有的返回类型
(1) Chain Result 就是返回一个类里 同时可以带参数进去
dashboard
/secure
(2)Dispatcher Result
就是个跳转 不过可以带着request的值 sendredirect 便不会带着request 只能是session的作用域
(3)FreeMarker Result 返回ftl 格式的模板
(4)
HttpHeader Result就是对http头 改变
204
a custom header value
another custom header value
305
this action must be accessed through a prozy
(5)
Redirect Result前面说个 不能传递request的值
<-- Pass parameters (reportType, width and height) -->
generateReport.jsp
/genReport
pie
100
100
(6)redirect action 就跳到action里
dashboard
/secure
<-- Redirect to an action in the same namespace -->
<-- Pass parameters (reportType, width and height) -->
generateReport
/genReport
pie
100
100
(7) streat result 跳到流文件
image/jpeg
imageStream
filename="document.pdf"
1024
(8)Velocity Result vm模板
foo.vm
(9)xslt
用xslt 格式化输出
foo.xslt
^/result/[^/*]$
.*(hugeCollection).*
(9)PlainText Result
/myJspFile.jsp
UTF-8