Struts2零碎点整理
1. 关于 Struts2 请求的扩展名问题
1). org.apache.struts2 包下的 default.properties 中配置了 Struts2 应用的一些常量
2). struts.action.extension 定义了当前 Struts2 应用可以接受的请求的扩展名.
3). 可以在 struts.xml 文件中以常量配置的方式修改 default.properties 所配置的常量.
<constant name="struts.action.extension" value="action,do,"></constant>
2. ActionSupport类
1). ActionSupport 是默认的 Action 类: 若某个 action 节点没有配置 class 属性, 则 ActionSupport 即为
待执行的 Action 类. 而 execute 方法即为要默认执行的 action 方法
<action name="testActionSupport">
<result>/testActionSupport.jsp</result>
</action>
等同于
<action name="testActionSupport"
class="com.opensymphony.xwork2.ActionSupport"
method="execute">
<result>/testActionSupport.jsp</result>
</action>
2). 在手工完成字段验证, 显示错误消息, 国际化等情况下, 推荐继承 ActionSupport.
3. result节点的相关配置介绍
1). result 是 action 节点的子节点
2). result 代表 action 方法执行后, 可能去的一个目的地
3). 一个 action 节点可以配置多个 result 子节点.
4). result 的 name 属性值对应着 action 方法可能有的一个返回值.
<result name="index">/index.jsp</result>
5). result 一共有 2 个属性, 还有一个是 type: 表示结果的响应类型
6). result 的 type 属性值在 struts-default 包的 result-types 节点的 name 属性中定义.
常用的有
> dispatcher(默认的): 转发. 同 Servlet 中的转发.
> redirect: 重定向
> redirectAction: 重定向到一个 Action
注意: 通过 redirect 的响应类型也可以便捷的实现 redirectAction 的功能!
<result name="index" type="redirectAction">
<param name="actionName">testAction</param>
<param name="namespace">/user</param>
</result>
或者
<result name="index" type="redirect">/user/testAction.do</result>
> chain: 转发到一个 Action
注意: 不能通过 type=dispatcher 的方式转发到一个 Action,
只能是:
<result name="test" type="chain">
<param name="actionName">testAction</param>
<param name="namespace">/user</param>
</result>
不能是:
<result name="test">/atguigu/testAction.do</result>
3 动态方法调用:
示例:
<package name="default" namespace="/" extends="struts-default">
<!-- 配置一个action 一个struts2的请求就是一个action
name属性:对应一个struts2请求的名字,不包含扩展名
result元素用来配置结果
-->
<action name="product" class="com.elgin.entity.Product">
<result name="details">/details.jsp</result>
</action>
</package>
如果想要打开使用,将上述的value配置为true即可,但是不推荐!
4 声明式异常处理
配置当前 action
的声明式异常处理
2 个属性
该结果将在捕获到指定异常时被执行,
既可以来自当前 action
的声明, 也可以来自
global-results声明.
但在 global-exception-mappings
元素下声明的任何 exception-mapping
元素只能引用在 global-results元素下声明的某个
result 元素
当某个 exception-mapping
元素声明的异常被捕获到时,
ExceptionMappingInterceptor拦截器就会向
ValueStack中添加两个对象:
表示被捕获异常的 Exception
对象
包含着被捕获异常的栈
可以在视图上通过 <s:property>
标签显示异常消息
Struts2零碎点整理的更多相关文章
- Struts2学习笔记整理(一)
最近在学习框架,很多人建议我直接学SSM,SSM看了一段时间后发现很多东西虽然可以用了,但是并不是很了解,所以我打算重新来过.从SSH开始学习,前面已经大致的学习了Hibernate,对于Hibern ...
- Struts2学习笔记整理(三)
Struts2的输入校验 之前对请求参数的输入校验一般分为两部分:1.客户端校验,也就是我们写js代码去对客户的误操作进行过滤 2.服务端校验, 这是整个应用组织非法数据的最后防线. Struts2 ...
- Struts2学习笔记整理(二)
这里是重点. Action接口 struts2 的Action可以是POJO 为了让用户开发的Action更加规范struts2提供了一个Action接口 ActionSupport基类 Struts ...
- Struts2学习笔记整理(四)
Struts2上传下载 文件上传 如果想使用HTML表单上传文件(一个或多个),那么必须把HTML表单的enctype属性设置成multipart/form-data,且method=post, 且使 ...
- struts2知识系统整理
1.MVC 和 JSP Model 2 ** a.:M-Model 模型 包含两部分:业务数据和业务处理逻辑 b.V-View 视图:视图(View)的职责是负责显示界面和用户交互(收集用户信息 ...
- Struts2标签库整理【完整】
转自:https://blog.csdn.net/chen_zw/article/details/8161230 Struts2标签库提供了主题.模板支持,极大地简化了视图页面的编写,而且,str ...
- IOS零碎技术整理(3)-获取wifi列表
1. 该功能实现基于MobileApple80211框架来进行开发,而目前该框架成为了私有框架,其中的API均为私有API. 如果使用这些API可能导致应用不能上app store或者ios版本升 ...
- IOS零碎技术整理(2)-隐藏系统Tabbar
原理就是将tabbar移出显示区 -(void)hideSystemTabBar:(UITabBar*) tabbarcontroller { [UIView beginAnimations:nil ...
- IOS零碎技术整理(1)-后台运行
这两天做关于离线通知的功能,总结了一点关于这方面的注意点:按Home键回到桌面后程序很快被挂起,系统将关闭程序的Socket监听,此时程序将不能继续执行网络请求等操作. 两种方式可以使程序继续存活一段 ...
随机推荐
- AsciiDoc Markup Syntax Summary
AsciiDoc Markup Syntax Summary ============================== A summary of the most commonly used ma ...
- 在CentOS 6.X 上面安装 Python 2.7.X
在CentOS 6.X 上面安装 Python 2.7.X CentOS 6.X 自带的python版本是 2.6 , 由于工作需要,很多时候需要2.7版本.所以需要进行版本升级.由于一些系统工具和服 ...
- Android应用程序中应用图标和名字的设置
在AndroidManifest.xml文件中设android:icon和 android:label指定名字和图标的位置,如: <application android:icon=" ...
- grunt + compass
compass和sass文章列表:http://182.92.240.72/tag/compass/ compass实战grunt: http://wrox.cn/article/2000491/ h ...
- git push 提示
我运行git push -u origin master 时提示如下: To git@github.com:userName/project.git ! [rejected] master -> ...
- Java关键字static、final使用小结
static 1. static变量 按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或类变量:另一种是没有被static修饰的变量,叫实例变量.两者的 ...
- LA 3029 - City Game (简单扫描线)
题目链接 题意:给一个m*n的矩阵, 其中一些格子是空地(F), 其他是障碍(R).找一个全部由F 组成的面积最大的子矩阵, 输出其面积乘以3的结果. 思路:如果用枚举的方法,时间复杂度是O(m^2 ...
- 函数fsp_get_space_header
/**********************************************************************//** Gets a pointer to the sp ...
- AI 行为树
by AKara 2010-12-09 @ http://blog.csdn.net/akara @ akarachen(at)gmail.com @weibo.com/akaras 谈到游戏AI,很 ...
- 【转】No JVM could be found on your system解决方法
原文网址:http://my.oschina.net/liusicong/blog/324964 在安装android studio时,报错: Error launching android Stud ...