struts的validate问题,validation.xml问题validator-rules.xml validator-rules.xml已经写好了常用的校验,你可以在这个文件里添加自己的校验方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 正则表达式也可以看明白的(呵呵`~部分部分)象暗码一样。那ruler你用就是了 一定好用的。 Validator中javascript的使用1. 在struts-config.xml中加入validator的plug-in. <!-- Validator的配置--> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"><set-property property="pathnames"value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> 2.在文件/WEB-INF/validation.xml中是我们要定义自己的验证规则 <form-validation> <!-- ========== Default Global Definitions ===================== --> <global> <constant> <constant-name>userID</constant-name> <constant-value>^\d{5}\d*$</constant-value> </constant> <constant> <constant-name>password</constant-name> <constant-value></constant-value> </constant> </global> <!-- ========== Default Language Form Definitions ===================== --> <formset> <form name="loginActionForm"> <field property="userID" depends="required"> <arg0 key="login.jsp.prompt.username"/> </field> <field property="password" depends="required,mask"> <arg0 key="login.jsp.prompt.password"/> <var> <var-name>mask</var-name> <var-value>^[0-9a-zA-Z]*$</var-value> </var> </field> </form> </formset> </form-validation>3. 在浏览器端使用JavaScript进行验证<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html:javascript formName="loginActionForm"/><html:html><head><title><bean:message key="login.jsp.title"/></title><html:base/></head><body><html:form action="/loginAction.do" focus="userid" onsubmit="return validateLoginActionForm(this);" method="post"> <div align="center"> <table width="22%" border="4"> <tr> <td height="208"><div align="left"> <table width="69%" border="0"> <tr> <td><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.username"/></font><strong> </strong></font></td> </tr> <tr> <td><div align="left"> <html:text property="userID" maxlength="40"/> </div></td> </tr> <tr> <td height="18"><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.password"/><strong> </strong></font></font> </td> </tr> <tr> <td><div align="center"> <html:password property="password" maxlength="10"/> </div></td> </tr> </table> <table width="69%" border="0"> <tr> <td height="38"><div align="right"> <html:submit><bean:message key="login.jsp.prompt.submit"/></html:submit> </div></td> <td><html:button property="close" onclick="window.close()"><bean:message key="login.jsp.prompt.close"/></html:button></td> </tr> </table> </div></td> </table> </div> </html:form></body></html:html>(http://blog.csdn.net/arqui/archive/2004/10/12/133717.aspx) 100分求两行数据找相同元素 s:if 中如何调用js函数 还是语言问题 求 java 将flash写入 pdf解决方案 有关hibernate下载的问题 【求教】spring aop 中 @afterreturnning 如何同时取得返回值和方法参数! 关于ssh的一些想法 struts2 +Spirng 2+hibernate3+tomcat6+mysql5.0 中文乱码问题 为什么用session把物品添加进去,再添加第二个的时候session自动刷新了? SSH集成失败 tomcat高手救命啊 jsp编译时报错
Validator中javascript的使用1. 在struts-config.xml中加入validator的plug-in. <!-- Validator的配置--> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"><set-property property="pathnames"value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in> 2.在文件/WEB-INF/validation.xml中是我们要定义自己的验证规则 <form-validation> <!-- ========== Default Global Definitions ===================== -->
<global>
<constant>
<constant-name>userID</constant-name>
<constant-value>^\d{5}\d*$</constant-value>
</constant>
<constant>
<constant-name>password</constant-name>
<constant-value></constant-value>
</constant>
</global>
<!-- ========== Default Language Form Definitions ===================== -->
<formset>
<form name="loginActionForm">
<field
property="userID"
depends="required">
<arg0 key="login.jsp.prompt.username"/>
</field>
<field
property="password"
depends="required,mask">
<arg0 key="login.jsp.prompt.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>
</formset>
</form-validation>3. 在浏览器端使用JavaScript进行验证
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html:javascript formName="loginActionForm"/>
<html:html>
<head>
<title><bean:message key="login.jsp.title"/></title>
<html:base/>
</head>
<body>
<html:form action="/loginAction.do" focus="userid" onsubmit="return validateLoginActionForm(this);" method="post">
<div align="center">
<table width="22%" border="4">
<tr>
<td height="208"><div align="left">
<table width="69%" border="0">
<tr>
<td><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.username"/></font><strong>
</strong></font></td>
</tr>
<tr>
<td><div align="left">
<html:text property="userID" maxlength="40"/>
</div></td>
</tr>
<tr>
<td height="18"><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.password"/><strong>
</strong></font></font> </td>
</tr>
<tr>
<td><div align="center">
<html:password property="password" maxlength="10"/>
</div></td>
</tr>
</table>
<table width="69%" border="0">
<tr>
<td height="38"><div align="right">
<html:submit><bean:message key="login.jsp.prompt.submit"/></html:submit>
</div></td>
<td><html:button property="close" onclick="window.close()"><bean:message key="login.jsp.prompt.close"/></html:button></td>
</tr>
</table>
</div></td> </table>
</div> </html:form></body>
</html:html>(http://blog.csdn.net/arqui/archive/2004/10/12/133717.aspx)