Struts第四天

来源:互联网 发布:知画生孩子视频 编辑:程序博客网 时间:2024/06/05 17:50

validation流程:

在struts-config.xml注册validation

 

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

这个注意的是要放在最后,因为在Struts里要生成基本的类的时候才可以读取validation插件

 

2.在validation.xml里写条件

 

配置文件:

errors.required={0} can not be blank!
errors.minlength={0} can not less than {1} charactors
errors.maxlength={0} can not be greater than {2} characters.

就可以进行变淡验证!

JSP:

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
 <html:base />

 <title>register.jsp</title>

 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">
 <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->

</head>

<body>
 <form method="post" action="register.do" name="registerForm">
  <p>
   &nbsp;姓名:
   <input type="text" name="username"><html:errors property="username"/>
  </p>
  <p>
   &nbsp;密码:
   <input type="text" name="password"><html:errors property="password"/>
  </p>
  <p>
   &nbsp;重复密码:
   <input type="text" name="repassword">
  </p>
  <p>
   &nbsp;年龄:
   <input type="text" name="age">
  </p>
  <p>
   &nbsp;
   <input type="submit" value="register" name="okBtn">
   <br>
  </p>
 </form>
</body>
</html:html>

 

struts-config.xml:

 

 

 

原创粉丝点击