zoukankan      html  css  js  c++  java
  • struts2的验证框架

    1、校验,struts2提供的多种校验方式:
    *验证Action中全部方法
    在Action同包下,创建:Action类名-validation.xml如:LoginAction创建LoginAction-validation.xml
    在这里LoginAction只有一个方法那就是login方法,当我们访问login方法的时候,struts2中的验证拦截器
    就会加载LoginAction-validation.xml的配置文件进行验证
    局限:如果action有其他方法,当我们访问这些方法,拦截器一样会进行验证操作,然后就会跳到input指定的错误页面;
     而我们的需求是这些方法不用进行验证,于是就有了下面这个方法
    *验证Action中单个方法
    每个方法单独配置一个validation.xml
    具体:在Action同包下,创建:Action类名-action方法对应的名称-validation.xml
    例如:<action name="userAction_*" method="{1}" class="struts2.action.UserAction">
     要创建UserAction-userAction_doAdd-validation.xml,userAction_doAdd为访问这个action方法的路径




    2、struts2 中同一个action的实现中对应多个input的处理方法  
    (1)解决方法:在方法上加上
    @InputConfig(resultName = "addInput")/@InputConfig(methodName="addInput")   
    public String doAdd(){
    @InputConfig(resultName = "editInput")
    public String doEdit(){
    (2)然后在struts.xml配置文件中添加:
             <result name="input">WEB-INF/user/error.jsp</result>
    <result name="addInput">WEB-INF/user/add.jsp</result>
    <result name="editInput">WEB-INF/user/edit.jsp</result>
    (3)原理:
          之所以通过上面的方式可以解决,主要如下的几个实现 
          com.opensymphony.xwork2.interceptor.annotations.InputConfig 
          com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor#doIntercept 


  • 相关阅读:
    Protocol Buffer技术详解(语言规范)
    google protobuf 简单实例
    advStringGrid单元格文字垂直居中
    java中两个字符串如何比较大小
    List集合去除重复对象及equals()、hashCode()方法的作用
    Delphi中使用ActiveX的一些心得
    java List去重方式及效率对比
    Visual Studio Code 调整字体大小
    用最简单的例子实现jQuery图片即时上传
    Linux下绝对经典的命令
  • 原文地址:https://www.cnblogs.com/kuyuyingzi/p/4266381.html
Copyright © 2011-2022 走看看