zoukankan      html  css  js  c++  java
  • Struts2验证框架的注意事项

    在编写struts2 的验证框架的时候 需要注意几点 

       1.编写的验证框架的配置文件要和被验证的Action的名称有一定的联系 

        age:Acton的名称:LoginUserAction  配置文件名:LoignUserAction-validation.xml 

        当Action里面得方法不止一个的时候 并且其他的方法不需要验证的时候 

        此时配置文件名为:LoginUserAction-mthodName-validation.xml    age(LoginUserAction-add-validation.xml) 

        【注意】 书写名称是时候要严格的按照此规则命名 并且 Action和对应的配置文件应在同一目录下 

       2.在Action中要定义相应的属性的取值方法 以便验证框架进行取值 

       3.在struts2.xml的配置文件中 相应的Action中要添加 

        <result name="input">源点</result> 

        【注意】 这个result的作用就是当验证失败的时候 要去的地方  多数情况下位 源点。 



        其中的难点就是 ActionName-methodName-validation.xml 文件格式的书写 

        age: 

        <?xml version="1.0" encoding="UTF-8"?> 
        <!DOCTYPE validators PUBLIC 
            "-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
               "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> 
        <validators> 
             <field name="userName"> 
                  <field-validator type="requiredstring"> 
                       <message> 错误提示信息 用户名不能为空</message> 
                  </field-validator> 
            </field> 
            <field name="pwd"> 
                  <field-validator type="requiredstring"> 
                       <message>错误提示信息 密码不能为空</message> 
                  </field-validator> 
            </field> 
        </validators> 



    【注意】 

        如果错误提示信息 不是在配置文件中而是在 另一个配置文件中 message.properties 文件中 

        这是需要在struts.xml文件中引入该文件 

        <constant name="struts.custon.I18n.resources" value="message"></constant> 

        这也是在Struts2 中声明常量的方法 

    在编写struts2 的验证框架的时候 需要注意几点 

       1.编写的验证框架的配置文件要和被验证的Action的名称有一定的联系 

        age:Acton的名称:LoginUserAction  配置文件名:LoignUserAction-validation.xml 

        当Action里面得方法不止一个的时候 并且其他的方法不需要验证的时候 

        此时配置文件名为:LoginUserAction-mthodName-validation.xml    age(LoginUserAction-add-validation.xml) 

        【注意】 书写名称是时候要严格的按照此规则命名 并且 Action和对应的配置文件应在同一目录下 

       2.在Action中要定义相应的属性的取值方法 以便验证框架进行取值 

       3.在struts2.xml的配置文件中 相应的Action中要添加 

        <result name="input">源点</result> 

        【注意】 这个result的作用就是当验证失败的时候 要去的地方  多数情况下位 源点。 



        其中的难点就是 ActionName-methodName-validation.xml 文件格式的书写 

        age: 

        <?xml version="1.0" encoding="UTF-8"?> 
        <!DOCTYPE validators PUBLIC 
            "-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
               "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> 
        <validators> 
             <field name="userName"> 
                  <field-validator type="requiredstring"> 
                       <message> 错误提示信息 用户名不能为空</message> 
                  </field-validator> 
            </field> 
            <field name="pwd"> 
                  <field-validator type="requiredstring"> 
                       <message>错误提示信息 密码不能为空</message> 
                  </field-validator> 
            </field> 
        </validators> 



    【注意】 

        如果错误提示信息 不是在配置文件中而是在 另一个配置文件中 message.properties 文件中 

        这是需要在struts.xml文件中引入该文件 

        <constant name="struts.custon.I18n.resources" value="message"></constant> 

        这也是在Struts2 中声明常量的方法

  • 相关阅读:
    CS224n, lec 10, NMT & Seq2Seq Attn
    CS231n笔记 Lecture 11, Detection and Segmentation
    CS231n笔记 Lecture 10, Recurrent Neural Networks
    CS231n笔记 Lecture 9, CNN Architectures
    CS231n笔记 Lecture 8, Deep Learning Software
    CS231n笔记 Lecture 7, Training Neural Networks, Part 2
    pytorch坑点排雷
    Sorry, Ubuntu 17.10 has experienced an internal error
    VSCode配置python插件
    tmux配置与使用
  • 原文地址:https://www.cnblogs.com/smilesmile/p/3860994.html
Copyright © 2011-2022 走看看