validation.xml内容如下:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"><form-validation>
<global>
<constant>
<constant-name>DATEFORMAT</constant-name>
<constant-value>yyyy/MM/dd</constant-value>
</constant>
<constant>
<constant-name>USERIDMASK</constant-name>
<constant-value>^([a-z0-9A-Z]|-|_)*$</constant-value>
</constant>
</global> <formset>
<form name="/login">
<field property="userId" depends="required,mask">
<msg name="required" key="validate.item.required" />
<arg0 key="login.user.id" />
<msg name="mask" key="validate.item.user.id.mask" />
<arg0 key="login.user.id" />
<var>
<var-name>mask</var-name>
<var-value>${USERIDMASK}</var-value>
</var>
</field>
<field property="userPwd" depends="required">
<msg name="required" key="validate.item.required" />
<arg0 key="login.user.pwd" />
</field>
</form>
</formset>
</form-validation>jsp内容如下:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <html:html>
<head>
<title><bean:message bundle="Page" key="system.title" /></title>
<link rel="stylesheet" href="/SZK/css/default.css" type="text/css" />
<script src="/SZK/js/default.js" language="JavaScript1.1"></script>
</head><body class="body">
<html:javascript formName="/login" method="validateLogin" dynamicJavascript="true" staticJavascript="false"/>
<html:form name="loginForm" type="com.szk.struts.form.sc.LoginForm" method="post" action="/login">
<%@ include file="Title.jsp"%>
<br>
<br>
<html:errors/>
<br>
<br>
<table width="330" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="65"> </td>
<td width="65" class="item"><bean:message bundle="Page" key="login.user.id" /></td>
<td width="180"><html:text property="userId" maxlength="10" style="width:105pt"/></td>
</tr>
<tr>
<td width="65"> </td>
<td width="70" class="item"><bean:message bundle="Page" key="login.user.pwd" /></td>
<td width="172"><html:password property="userPwd" maxlength="16" style="width:105pt"/></td>
</tr>
</table>
<br>
<table width="330" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="119"> </td>
<td width="90" align="right"><html:submit onclick="return validateLogin(document.loginForm)"><bean:message bundle="Page" key="button.login" /></html:submit></td>
<td width="2"> </td>
<td width="129"><html:reset><bean:message bundle="Page" key="button.reset" /></html:reset></td>
</tr>
</table>
</body>
</html:form>
</html:html>errrors.properties内容如下:
# Resources for parameter 'com.szk.struts.CheckMessage'
# Project P/SZK#validate check
validate.item.required={0}\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u8bf7\u8f93\u5165\uff01
validate.item.user.id.mask={0}\u683c\u5f0f\u4e0d\u5bf9\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01#login.jsp
login.user.id=\u7528\u6237ID
login.user.pwd=\u7528\u6237\u5bc6\u7801Check先进行客户端Check,在进行服务器端Check!
当进行服务器端Check时,画面内容都没有输入,错误信息会在一行中显示,如果将错误信息分行显示.
客户端和服务器端信息都要按行显示错误信息,怎么做,请高手帮忙,在先等待..................
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"><form-validation>
<global>
<constant>
<constant-name>DATEFORMAT</constant-name>
<constant-value>yyyy/MM/dd</constant-value>
</constant>
<constant>
<constant-name>USERIDMASK</constant-name>
<constant-value>^([a-z0-9A-Z]|-|_)*$</constant-value>
</constant>
</global> <formset>
<form name="/login">
<field property="userId" depends="required,mask">
<msg name="required" key="validate.item.required" />
<arg0 key="login.user.id" />
<msg name="mask" key="validate.item.user.id.mask" />
<arg0 key="login.user.id" />
<var>
<var-name>mask</var-name>
<var-value>${USERIDMASK}</var-value>
</var>
</field>
<field property="userPwd" depends="required">
<msg name="required" key="validate.item.required" />
<arg0 key="login.user.pwd" />
</field>
</form>
</formset>
</form-validation>jsp内容如下:
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <html:html>
<head>
<title><bean:message bundle="Page" key="system.title" /></title>
<link rel="stylesheet" href="/SZK/css/default.css" type="text/css" />
<script src="/SZK/js/default.js" language="JavaScript1.1"></script>
</head><body class="body">
<html:javascript formName="/login" method="validateLogin" dynamicJavascript="true" staticJavascript="false"/>
<html:form name="loginForm" type="com.szk.struts.form.sc.LoginForm" method="post" action="/login">
<%@ include file="Title.jsp"%>
<br>
<br>
<html:errors/>
<br>
<br>
<table width="330" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="65"> </td>
<td width="65" class="item"><bean:message bundle="Page" key="login.user.id" /></td>
<td width="180"><html:text property="userId" maxlength="10" style="width:105pt"/></td>
</tr>
<tr>
<td width="65"> </td>
<td width="70" class="item"><bean:message bundle="Page" key="login.user.pwd" /></td>
<td width="172"><html:password property="userPwd" maxlength="16" style="width:105pt"/></td>
</tr>
</table>
<br>
<table width="330" align="center" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="119"> </td>
<td width="90" align="right"><html:submit onclick="return validateLogin(document.loginForm)"><bean:message bundle="Page" key="button.login" /></html:submit></td>
<td width="2"> </td>
<td width="129"><html:reset><bean:message bundle="Page" key="button.reset" /></html:reset></td>
</tr>
</table>
</body>
</html:form>
</html:html>errrors.properties内容如下:
# Resources for parameter 'com.szk.struts.CheckMessage'
# Project P/SZK#validate check
validate.item.required={0}\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u8bf7\u8f93\u5165\uff01
validate.item.user.id.mask={0}\u683c\u5f0f\u4e0d\u5bf9\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff01#login.jsp
login.user.id=\u7528\u6237ID
login.user.pwd=\u7528\u6237\u5bc6\u7801Check先进行客户端Check,在进行服务器端Check!
当进行服务器端Check时,画面内容都没有输入,错误信息会在一行中显示,如果将错误信息分行显示.
客户端和服务器端信息都要按行显示错误信息,怎么做,请高手帮忙,在先等待..................
errors.footer=<hr>
看看我这个实现过的例子
validation.xml:
<form name="movementForm">
<field property="movementSubject" depends="required">
<arg0 key="label.movementSubject"/>
</field>
<field property="movementTime" depends="date">
<arg0 key="label.movementTime"/>
</field>
<field property="movementAddress" depends="required">
<arg0 key="label.movementAddress"/>
</field>
</form>资源文件 resources.properties
label.movementSubject=\u6d3b\u52a8\u4e3b\u9898
label.movementTime=\u6d3b\u52a8\u65f6\u95f4
label.movementAddress=\u6d3b\u52a8\u5730\u70b9在config.xml做如下配置
<action path="/dailyWork" name="movementForm" input="failure"
validate="true" type="com.action.DailyWorkAction"> //validate="true"
<forward name="success" path="/DailyWorkBaseinfo.jsp"/>
<forward name="unsuccess" path="/../error.jsp"/>
</action><message-resources parameter="com.resources.properties"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>jsp 文件
<html:text name="movementForm" property="movementSubject" style="width:100%;" />
<font color="FF0000"><html:errors property="movementSubject"/></font>