关于struts2的一些问题
1.如果action中使用了validate方法并且同时配置了xml文件校验框架,则会先从校验框架判断输入错误,然后转入validate方法中去继续执行直到该方法return、方法执行结束、遇到执行fieldError()或actionError()这三种情况,因此两边的错误信息都会显示出来。因此不推荐同时使用这两种校验方式,此外对于validate方法中如果出现actionError或fieldError则返回INPUT的result视图,但是在execute或其它action method方法中,则不会返回,而是会继续执行直到抛出异常或方法执行结束、以及遇到显示的return值。
?
2.struts配置文件搜索顺序
struts.xml
struts-plugin-xml
struts.properties
web.xml
?
3.action配置节点默认值
name无默认值,必须定义
class:com.opensymphony.xwork2.ActionSupport
method:execute
result:success
因此若忽略class、method及result.name的配置,即使用默认,将直接转向result目标地址
?
4.struts标签中使用el表达式抛出的异常
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
参见:http://blog.csdn.net/totogogo/archive/2008/03/07/2157448.aspx
http://coffeesweet.iteye.com/blog/710405
原因:coffeesweet 写道
<action name="user_add" method="add">?
7.要使action类自动执行validate放发必须实现com.opensymphony.xwork2.Validateable接口,该接口只有一个方法:public void validate();如果已经继承了ActionSupport类(该类实现了Validateable接口),则无需再实现Validateable接口,当action执行的时候将在调用execute方法(或其他自定义方法)之前自动执行validate方法已实现一些前置校验功能。
参考:http://book.51cto.com/art/200904/119408.htm
http://terryjs.iteye.com/blog/768637
?
?
?附录:附上一些从传智播客Struts_2.1.8中截取的图片,如有侵权,请指出,本人将立即删除。
1.搭建Struts2开发环境——Struts2在Web中的启动配置
2.Action名称的搜索顺序
3.Action中各种result转发类型

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?