我正在尝试使用 Struts 验证来检查用户输入的各个字段。如果有人能够帮助我了解我所缺乏的东西,我将非常感激。这是我所拥有的:
我放入validation.xml
并TestAction-validation.xml
放入WEB-INF/classes/
这里是validation.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator Config 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd">
<validators>
<validator name="int" class="com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
. . .
</validators>
这里是TestAction-validation.xml
:
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="testInt">
<field-validator type="int">
<param name="min">0</param>
<param name="max">9</param>
<message>Number not in range</message>
</field-validator>
</field>
<field name="testString">
<field-validator type="stringlength">
<param name="minLength">4</param>
<message>String not long enough.</message>
</field-validator>
</field>
</validators>
我的struts.xml
扩展struts-default
,我有一个非常简单的动作类TestAction
,它扩展ActionSupport
并具有字段testInt
和testString
.
根据我的阅读,这应该足以让 Struts 检查输入的值,但它没有发生。我错过了什么?