« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
|
统计 |
blog名称:小雨 日志总数:262 评论数量:1273 留言数量:15 访问次数:4673499 建立时间:2005年1月8日 |
| 
|
W3CHINA Blog首页 管理页面 写新日志 退出
[知识积累]有验证返回消息的 struts |
小雨 发表于 2007/12/8 16:51:57 |
1 资源文件MessageResources.properties
# Licensed to the Apache Software Foundation (ASF) under one or more# contributor license agreements. See the NOTICE file distributed with# this work for additional information regarding copyright ownership.# The ASF licenses this file to You under the Apache License, Version 2.0# (the "License"); you may not use this file except in compliance with# the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.
# -- Standard Errors --errors.header=<ul>errors.prefix=<li class="error">errors.suffix=</li>errors.footer=</ul>
# -- Struts Validator Error Messages --errors.required={0} is required.# mask 实际上是invalid的错误消息 是由validator-rules.xml设定的errors.invalid={0} is invalid.
# -- buttons --button.submit=Submit
# -- prompts --prompt.logName=Nameprompt.passWord=pass Wordprompt.mask=mask
2 validation.xml
<?xml version="1.0" encoding="ISO-8859-1" ?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.-->
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">
<form-validation>
<!-- This is a minimal Validator form file with a couple of examples.-->
<global>
<!-- An example global constant <constant> <constant-name>postalCode</constant-name> <constant-value>^\d{5}\d*$</constant-value> </constant> end example-->
</global>
<formset>
<!-- An example form --> <form name="simpleForm"> <field property="logName" depends="required"> <arg key="prompt.logName"/> </field> <field property="passWord" depends="mask,required"> <arg key="prompt.mask" /> <var> <var-name>mask</var-name> <var-value>^\d{5}\d*$</var-value> </var>
</field> </form> </formset></form-validation>
3validator-rules.xml
<?xml version="1.0" encoding="ISO-8859-1" ?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.-->
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans> <form-bean name="simpleForm" type="org.cjea.Struts.example.RegUserForm"/> </form-beans> <action-mappings> <action path="/RegUser" type="org.cjea.Struts.example.RegUserAction" name="simpleForm" scope="request" input="/index.jsp" validate="true"> <forward name="success" path="/html-good.jsp"/> <forward name="fails" path="/html-error.jsp"/> </action> </action-mappings>
<message-resources parameter="org.MessageResources" /> <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-config>
|
阅读全文(3628) | 回复(1) | 编辑 | 精华 |
回复:有验证返回消息的 struts |
小雨发表评论于2007/12/10 14:52:54 |
资源文件中的中文问题http://www.huuoo.com/thread-15346-1-1.html
native2ascii -encoding gbk MessageResources.properties temp.properties
native2ascii 工具在jdk\bin目录下
这里将根据MessageResources.properties输出了一个临时文件temp.properties,然后把MessageResources.properties中的文件内容替换为这个临时文件的内容就可以了。( M4
|
个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除 |
» 1 »
|