ImageVerifierCode 换一换
格式:PPT , 页数:21 ,大小:284KB ,
资源ID:7929108      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-7929108.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(strut讲义 struts8_validator框架.ppt)为本站会员(gnk289057)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

strut讲义 struts8_validator框架.ppt

1、Validator验证框架,2,ActionForm生命周期流程图,3,Why Struts Validation Framework,Issues with writing validate() method in ActionForm classes You have to write validate() method for each ActionForm class, which results in redundant code Changing validation logic requires recompiling Struts validation framework ad

2、dresses these issues Validation logic is configured using built-in validation rules as opposed to writing it in Java code,4,What Struts Validation Framework Is,Validator主要依赖两个jar包 Jakarta-oro.jar:提供一组处理文本的类,具有文本替换、过滤、和分割功能。 Commons-validator.jar:提供了一个简单、可扩展的验证框架,包含了通用的验证方法和验证规则。 Struts 1.1 includes

3、this by default Allows declarative validation for many fields Formats Dates, Numbers, Email, Credit Card, Postal Codes Lengths Minimum, maximum Ranges,5,What Struts Validation Framework Is,Validator采用基于两个xml文件的方式来配置验证规则,分别为validation.xml,validator-rules.xml。在struts应用中,需放到web-inf目录下。 1validator-rules

4、.xml 这个文件包含了一组验证规则,对所有struts应用都适用。一般情况不用修改这个文件,除非要修改或扩展默认规则。 2validation.xml文件 这个文件是针对于具体struts应用的,可以为应用中的ActionForm配置验证规则。而不用编码实现验证。,6,Built-in Validation Rules in validator-rules.xml,required minlength,maxlength byte, short, integer, long, float, double date, range, intRange, floatRange creditCard

5、, email 等等,7,Part of WEB-INF/validator-rules.xml, ,8,Attributes of Validator,name: logical name of the validation rule classname, method: class and method that contains the validation logic methodParams: comma-delimited list of parameters for the method msg: key from the resource bundle Validator fr

6、amework uses this to look up a message from Struts resource bundle depends: other validation rules that should be called first,9,How to Use Validation Framework,Configure Validator plugin Configure validation.xml file (and validator-rules.xml file) Extend Validator ActionForms or Dynamic Validator A

7、ctionForms org.apache.struts.validator.ValidatorForm Org.apache.struts.validator.DynaValidatorForm Set validate=”true” on Action Mappings,10,Configure Validator in WEB-INF/struts-config.xml,11,扩展Struts框架,Struts1.1框架提供了动态插入和加载组件的功能,这种组件被成为Struts插件。Struts插件实际上就是一个Java类,它在Struts应用启动时被初始化,在应用关闭时被销毁。任何作为

8、插件的Java类都应该实现org.apache.struts.action.PlugIn接口。 public interface PlugIn public void init(ActionServlet servlet, ApplicationConfig config) throws ServletException;public void destroy(); 一个Struts应用可以包含一个或多个插件。在Struts应用启动时,Struts框架调用每个插件类的init()方法进行初始化。在插件的初始化阶段,可以完成一些初始化操作,如建立数据库连接,或者和远程系统的连接等。 当应用被关闭

9、时,Struts框架就会调用每个插件类的destroy()方法,destroy()方法可以用来完成释放资源的人物,如关闭数据库连接或远程系统连接等。 除了创建插件类外,还需要在Struts配置文件中配置插件,Struts框架在启动时将根据相关的配置信息来初始化插件。与插件对应的配置元素为。,12,Built-in Error Messages in validator-rules.xml,# Struts Validator Error Messageserrors.required=0 is required.errors.minlength=0 can not be less than 1

10、 characters.errors.maxlength=0 can not be greater than 1 characters.errors.invalid=0 is invalid.errors.byte=0 must be a byte.errors.short=0 must be a short.errors.integer=0 must be an integer.errors.long=0 must be a long.errors.float=0 must be a float.errors.double=0 must be a double.errors.date=0 i

11、s not a date.errors.range=0 is not in the range 1 through 2.errors.creditcard=0 is an invalid credit card number.errors.email=0 is an invalid e-mail address.,13,WEB-INF/validation.xml: validatorLoginForm,minlength 4 maxlength8,14,Corresponds to a property in an ActionFormAttributes property: name of

12、 a property (in an ActionForm) that is to be validated depends: comma-delimited list of validation rules to apply against this field All validation rules have to succeed,15,: ,Allows you to specify an alternate message for a field elementname: specifies rule with which the msg is used, should be one

13、 of the rules in validation-rules.xml key: specifies key from the resource bundle that should be added to the ActionError if validation fails resource: if set to false, the value of key is taken as literal string,16,: , Are used to pass additional values to the messageis the 1st replacement and is t

14、he 2nd replacement, and so on,17,: ,Set parameters that a field element may need to pass to one of its validation rules such as minimum and miximum values in a range validation Referenced by elements using $var:var-name syntax,18,ActionForm and Validator,You cannot use ActionForm class with the Vali

15、dator Instead you need to use special subclasses of ActionForm class Validator supports two types special ActionForms Standard ActionForms ValidatorForm Dynamic ActionForms DynaValidatorForm,19,Revised WEB-INF/struts-config.xml,20,Reversied,errors.required=0 is required. errors.minlength=0 can not b

16、e less than 1 characters. errors.maxlength=0 can not be greater than 1 characters. errors.invalid=0 is invalid.errors.byte=0 must be a byte. errors.short=0 must be a short. errors.integer=0 must be an integer. errors.long=0 must be a long. errors.float=0 must be a float. errors.double=0 must be a do

17、uble.errors.date=0 is not a date. errors.range=0 is not in the range 1 through 2. errors.creditcard=0 is an invalid credit card number. errors.email=0 is an invalid e-mail address.,Note: all messages are copied from the comments part of WEB-INF/validator-rules.xml,WEB-INF/classes/strutsweb/LoginReso

18、urces.properties,21,WEB-INF/classes/strutsweb /ValidatorLoginForm,package strutsweb;import org.apache.struts.validator.*; import org.apache.struts.action.*; import javax.servlet.http.*;public class ValidatorLoginForm extends ValidatorForm private String name;private String password;public String getName() return name;public void setName(String name) this.name = name;public String getPassword() return password;public void setPassword(String password) this.password = password;,

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报