站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2SE 专题如何用-lt;html:errors-gt;标签格式显示错误信息!郁闷很久了,请高手帮忙!

如何用-lt;html:errors-gt;标签格式显示错误信息!郁闷很久了,请高手帮忙!

摘要: 如何用-lt;html:errors-gt;标签格式显示错误信息!郁闷很久了,请高手帮忙!


validation.xml内容如下:
-#60;?xml version=-#34;1.0-#34; encoding=-#34;ISO-8859-1-#34; ?-#62;
-#60;!DOCTYPE form-validation PUBLIC
-#34;-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN-#34;
-#34;http://jakarta.apache.org/commons/dtds/validator_1_0.dtd-#34;-#62;

-#60;form-validation-#62;
-#60;global-#62;
-#60;constant-#62;
-#60;constant-name-#62;DATEFORMAT-#60;/constant-name-#62;
-#60;constant-value-#62;yyyy/MM/dd-#60;/constant-value-#62;
-#60;/constant-#62;
-#60;constant-#62;
-#60;constant-name-#62;USERIDMASK-#60;/constant-name-#62;
-#60;constant-value-#62;^([a-z0-9A-Z]|-|_)*$-#60;/constant-value-#62;
-#60;/constant-#62;
-#60;/global-#62;

-#60;formset-#62;
-#60;form name=-#34;/login-#34;-#62;
-#60;field property=-#34;userId-#34; depends=-#34;required,mask-#34;-#62;
-#60;msg name=-#34;required-#34; key=-#34;validate.item.required-#34; /-#62;
-#60;arg0 key=-#34;login.user.id-#34; /-#62;
-#60;msg name=-#34;mask-#34; key=-#34;validate.item.user.id.mask-#34; /-#62;
-#60;arg0 key=-#34;login.user.id-#34; /-#62;
-#60;var-#62;
-#60;var-name-#62;mask-#60;/var-name-#62;
-#60;var-value-#62;${USERIDMASK}-#60;/var-value-#62;
-#60;/var-#62;
-#60;/field-#62;
-#60;field property=-#34;userPwd-#34; depends=-#34;required-#34;-#62;
-#60;msg name=-#34;required-#34; key=-#34;validate.item.required-#34; /-#62;
-#60;arg0 key=-#34;login.user.pwd-#34; /-#62;
-#60;/field-#62;
-#60;/form-#62;
-#60;/formset-#62;
-#60;/form-validation-#62;

jsp内容如下:
-#60;%@ page contentType=-#34;text/html;charset=UTF-8-#34; %-#62;
-#60;%@ taglib uri=-#34;/WEB-INF/struts-bean.tld-#34; prefix=-#34;bean-#34;%-#62;
-#60;%@ taglib uri=-#34;/WEB-INF/struts-html.tld-#34; prefix=-#34;html-#34;%-#62;
-#60;%@ taglib uri=-#34;/WEB-INF/struts-logic.tld-#34; prefix=-#34;logic-#34;%-#62;

-#60;html:html-#62;
-#60;head-#62;
-#60;title-#62;-#60;bean:message bundle=-#34;Page-#34; key=-#34;system.title-#34; /-#62;-#60;/title-#62;
-#60;link rel=-#34;stylesheet-#34; href=-#34;/SZK/css/default.css-#34; type=-#34;text/css-#34; /-#62;
-#60;script src=-#34;/SZK/js/default.js-#34; language=-#34;JavaScript1.1-#34;-#62;-#60;/script-#62;
-#60;/head-#62;

-#60;body class=-#34;body-#34;-#62;
-#60;html:javascript formName=-#34;/login-#34; method=-#34;validateLogin-#34; dynamicJavascript=-#34;true-#34; staticJavascript=-#34;false-#34;/-#62;
-#60;html:form name=-#34;loginForm-#34; type=-#34;com.szk.struts.form.sc.LoginForm-#34; method=-#34;post-#34; action=-#34;/login-#34;-#62;
-#60;%@ include file=-#34;Title.jsp-#34;%-#62;
-#60;br/-#62;
-#60;br/-#62;
-#60;html:errors/-#62;
-#60;br/-#62;
-#60;br/-#62;
-#60;table width=-#34;330-#34; align=-#34;center-#34; border=-#34;0-#34; cellspacing=-#34;0-#34; cellpadding=-#34;0-#34;-#62;
-#60;tr-#62;
-#60;td width=-#34;65-#34;-#62;-#38;nbsp;-#60;/td-#62;
-#60;td width=-#34;65-#34; class=-#34;item-#34;-#62;-#60;bean:message bundle=-#34;Page-#34; key=-#34;login.user.id-#34; /-#62;-#60;/td-#62;
-#60;td width=-#34;180-#34;-#62;-#60;html:text property=-#34;userId-#34; maxlength=-#34;10-#34; style=-#34;width:105pt-#34;/-#62;-#60;/td-#62;
-#60;/tr-#62;
-#60;tr-#62;
-#60;td width=-#34;65-#34;-#62;-#38;nbsp;-#60;/td-#62;
-#60;td width=-#34;70-#34; class=-#34;item-#34;-#62;-#60;bean:message bundle=-#34;Page-#34; key=-#34;login.user.pwd-#34; /-#62;-#60;/td-#62;
-#60;td width=-#34;172-#34;-#62;-#60;html:password property=-#34;userPwd-#34; maxlength=-#34;16-#34; style=-#34;width:105pt-#34;/-#62;-#60;/td-#62;
-#60;/tr-#62;
-#60;/table-#62;
-#60;br/-#62;
-#60;table width=-#34;330-#34; align=-#34;center-#34; border=-#34;0-#34; cellspacing=-#34;0-#34; cellpadding=-#34;0-#34;-#62;
-#60;tr-#62;
-#60;td width=-#34;119-#34;-#62;-#38;nbsp;-#60;/td-#62;
-#60;td width=-#34;90-#34; align=-#34;right-#34;-#62;-#60;html:submit onclick=-#34;return validateLogin(document.loginForm)-#34;-#62;-#60;bean:message bundle=-#34;Page-#34; key=-#34;button.login-#34; /-#62;-#60;/html:submit-#62;-#60;/td-#62;
-#60;td width=-#34;2-#34;-#62;-#38;nbsp;-#60;/td-#62;
-#60;td width=-#34;129-#34;-#62;-#60;html:reset-#62;-#60;bean:message bundle=-#34;Page-#34; key=-#34;button.reset-#34; /-#62;-#60;/html:reset-#62;-#60;/td-#62;
-#60;/tr-#62;
-#60;/table-#62;
-#60;/body-#62;
-#60;/html:form-#62;
-#60;/html:html-#62;

errrors.properties内容如下:
# Resources for parameter -#39;com.szk.struts.CheckMessage-#39;
# 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/u7801

Check先进行客户端Check,在进行服务器端Check!
当进行服务器端Check时,画面内容都没有输入,错误信息会在一行中显示,如果将错误信息分行显示.
客户端和服务器端信息都要按行显示错误信息,怎么做,请高手帮忙,在先等待..................


你以下内容修正errrors.properties

error.global.fromform=-#60;li-#62;This is a global error -#60;/li-#62;
errors.footer=-#60;hr-#62;


楼上仁兄的方法我尝试过了,但在客户端Check,就是弹对话框那种,信息会显示-#60;li-#62;This is a global error -#60;/li-#62; 但-#60;li-#62;-#60;/li-#62;是不能要的啊。


试试 error.global.fromform=This is a global error-#60;br/-#62;



-#60;form name=-#34;/login-#34;-#62; -#60;!--这行有问题吧,这里是配置你页面用到的form---#62;


看看我这个实现过的例子
validation.xml:
-#60;form name=-#34;movementForm-#34;-#62;
-#60;field property=-#34;movementSubject-#34; depends=-#34;required-#34;-#62;
-#60;arg0 key=-#34;label.movementSubject-#34;/-#62;
-#60;/field-#62;
-#60;field property=-#34;movementTime-#34; depends=-#34;date-#34;-#62;
-#60;arg0 key=-#34;label.movementTime-#34;/-#62;
-#60;/field-#62;
-#60;field property=-#34;movementAddress-#34; depends=-#34;required-#34;-#62;
-#60;arg0 key=-#34;label.movementAddress-#34;/-#62;
-#60;/field-#62;
-#60;/form-#62;

资源文件 resources.properties
label.movementSubject=/u6d3b/u52a8/u4e3b/u9898
label.movementTime=/u6d3b/u52a8/u65f6/u95f4
label.movementAddress=/u6d3b/u52a8/u5730/u70b9

在config.xml做如下配置
-#60;action path=-#34;/dailyWork-#34; name=-#34;movementForm-#34; input=-#34;failure-#34;
validate=-#34;true-#34; type=-#34;com.action.DailyWorkAction-#34;-#62; //validate=-#34;true-#34;
-#60;forward name=-#34;success-#34; path=-#34;/DailyWorkBaseinfo.jsp-#34;/-#62;
-#60;forward name=-#34;unsuccess-#34; path=-#34;/../error.jsp-#34;/-#62;
-#60;/action-#62;

-#60;message-resources parameter=-#34;com.resources.properties-#34;/-#62;
-#60;plug-in className=-#34;org.apache.struts.validator.ValidatorPlugIn-#34;-#62;
-#60;set-property property=-#34;pathnames-#34; value=-#34;/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml-#34;/-#62;
-#60;/plug-in-#62;

jsp 文件
-#60;html:text name=-#34;movementForm-#34; property=-#34;movementSubject-#34; style=-#34;width:100%;-#34; /-#62;
-#60;font color=-#34;FF0000-#34;-#62;-#60;html:errors property=-#34;movementSubject-#34;/-#62;-#60;/font-#62;


↑返回目录
前一篇: 初学者的问题
后一篇: 一道简单的java程序出错, 为什么?