struts2视频学习错误记录1-7讲
2009-03-10 21:39
387 查看
第一讲:
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts.xml 在WebRoot/WEB-INF/classes下
<package name="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<result name="success">/result.jsp</result>
</action>
</package>
com.test.action.LoginAction 写属性的get set方法execute()返回string(result)
Struts 2.0有两个配置文件,struts.xml和struts.properties都是放在WEB-INF/classes/下。
1、struts.xml用于应用程序相关的配置
2、struts.properties用于Struts 2.0的运行时(Runtime)的配置
使用标签struts-tags
基本验证 validate()用到资源文件
addFieldError(String fieldName, String errorMessage) 错误信息显示在标签的上面
第二讲:类型转换开始
第三讲 类型转换续 转换的类继承DefaulttypeConverter 实现三个参数的方法
定义配置文件和action一个位置:actionName-conversion.properties
错误记录:不是下划线!-conversion.properties 的大小写要小写
显示的时候 <s:property value="name" /> name属性是错的。应该改成value属性
第四讲续类型转换 全局的类型转换配置文件xwork-conversion.properties 前面类名后面也类名
用strutsTypeConverter
还可以用类名点属性来在页面赋值,需要提供无参数的构造就不用转换了不推荐!
注册全局类型的转换时报下面的错 严重: Conversion registration error
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance
(InstantiationExceptionConstructorAccessorImpl.java:30)
现在没有查到原因。
意外知道一个别的知识:
If any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.
第五讲:输入校验
1.用struts2标签的时候action="login"可以。用标准的时候一定要写action="login.action"
2.出错提示的资源文件messages.properties(src下)这是全局的
xwork.default.invalid.fieldvalue={0} error
一定要写正确~
struts.xml中要配置<constant name="struts.custom.i18n.resources" value="messages"></constant>
局部的用ActionName.properties放在同包下
invalid.fieldvalue.name=saysomething
3. this.addActionError("errormessage");
method="mymethod" validate方法用validateMymethod();然后调用validate()方法不写即可
如果在action中有多个方法,但是要验证execute()方法时,写成validateExecute()即可
web.xml
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts.xml 在WebRoot/WEB-INF/classes下
<package name="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<result name="success">/result.jsp</result>
</action>
</package>
com.test.action.LoginAction 写属性的get set方法execute()返回string(result)
Struts 2.0有两个配置文件,struts.xml和struts.properties都是放在WEB-INF/classes/下。
1、struts.xml用于应用程序相关的配置
2、struts.properties用于Struts 2.0的运行时(Runtime)的配置
使用标签struts-tags
基本验证 validate()用到资源文件
addFieldError(String fieldName, String errorMessage) 错误信息显示在标签的上面
第二讲:类型转换开始
第三讲 类型转换续 转换的类继承DefaulttypeConverter 实现三个参数的方法
定义配置文件和action一个位置:actionName-conversion.properties
错误记录:不是下划线!-conversion.properties 的大小写要小写
显示的时候 <s:property value="name" /> name属性是错的。应该改成value属性
第四讲续类型转换 全局的类型转换配置文件xwork-conversion.properties 前面类名后面也类名
用strutsTypeConverter
还可以用类名点属性来在页面赋值,需要提供无参数的构造就不用转换了不推荐!
注册全局类型的转换时报下面的错 严重: Conversion registration error
java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance
(InstantiationExceptionConstructorAccessorImpl.java:30)
现在没有查到原因。
意外知道一个别的知识:
If any Struts 2 Plugins are included, then other JARs may be needed too. For example, the optional Spring Plugin requires the Spring JARs to be present.
第五讲:输入校验
1.用struts2标签的时候action="login"可以。用标准的时候一定要写action="login.action"
2.出错提示的资源文件messages.properties(src下)这是全局的
xwork.default.invalid.fieldvalue={0} error
一定要写正确~
struts.xml中要配置<constant name="struts.custom.i18n.resources" value="messages"></constant>
局部的用ActionName.properties放在同包下
invalid.fieldvalue.name=saysomething
3. this.addActionError("errormessage");
method="mymethod" validate方法用validateMymethod();然后调用validate()方法不写即可
如果在action中有多个方法,但是要验证execute()方法时,写成validateExecute()即可
相关文章推荐
- struts2视频学习记录第8 9讲
- 实例学习SSIS(四)-- 使用日志记录和错误流重定向
- Linux学习记录--开机挂载错误
- cmake 学习之路 记录中间所遇到过的所有错误与问题的解决 <一>
- struts2的dojo插件一些学习记录
- Struts2.x 学习笔记 之 错误消息提示和定制
- spark学习&错误记录
- 【Soot学习记录1】新Class文件的生成及错误处理
- cmake 学习之路 记录中间所遇到过的所有错误与问题的解决 <三>
- Python 学习笔记-错误记录
- [原创]java WEB学习笔记71:Struts2 学习之路-- struts2常见的内建验证程序及注意点,短路验证,非字段验证,错误消息的重用
- Sphinx语音识别学习记录 (五)-错误调试
- python学习错误记录——创建类中初始化函数注意点
- 记录学习的点滴(Struts2的Action配置)
- 【JavaEE企业应用实战学习记录】struts2登录
- 学习Struts2的记录
- Struts2.x 学习笔记 之 类型转换器 和 错误提示修改
- 黑马程序员视频学习下载地址记录一下
- Python学习之错误与解决记录
- struts2系列学习笔记(8)---------------类型转换的错误处理