struts本地验证服务器验证 过程如下

1 首先对项目加入struts支持

2 建立form bean ,其中type="org.apache.struts.validator.DynaValidatorForm"

3 在struts-config.xml配置文件中

在 <action-mappings >

      <action 后添加 input="/login.jsp" ,此路径为出错后返回的页面

     别且将后面的validate="false",把false改成true!

<message-resources parameter="com.accp.struts.ApplicationResources" />

后加上

 <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
   <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validator.xml"/>
 </plug-in>

 

4 在WEB-INF下创建validator.xml文件,加入:

<!DOCTYPE form-validation PUBLIC
          "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
          "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">

然后 下面写 form的名称和propertity以及约束内容

 约束内容 depends (可以在validator-rules.xml 看到所提供的约束)

 

<form-validation>
 <formset>
  <form name="userForm">
   <field property="uName" depends="required,integer">
    <msg name="${uName}" key="name.required" />
   </field>
   
  </form>
 </formset>

 

最后记得在 ApplicationResources.properties 加入erroes的定义

5 还可以在JSP页面加上标签

<html:javascript formName="userForm"/>

formName是form的名称

然后在form标签里 加入

onsubmit="return validateUserForm(this)"

同时实现js脚本验证!

 

 

 

转载请说明出处

相关文章:

  • 2021-06-30
  • 2021-11-23
  • 2021-11-23
  • 2021-09-10
  • 2021-11-01
  • 2021-12-10
  • 2022-12-23
  • 2021-05-04
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案