struts2 验证规则文件

1.先找到xml对应的文件信息

window->preference->Myeclipse Enterprise->Files and Editors->XML->XML catalog->User Specified Entries->add

 


struts2 验证规则文件_第1张图片
 

location的位置为:E:\java\struts-2.3.20\src\xwork-core\src\main\resources\xwork-validator-1.0.3.dtd

Key Type:Public ID

Key:  -//OpenSymphony Group//XWork Validator 1.0.3//EN(这个已经停止运营了,应该用新的,即后面的)或者 (-//Apache Struts//XWork Validator 1.0.3//EN)(新)

选中alternative web address: http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd

注:

struts2 验证规则文件_第2张图片
 
 

上述validation.xml文件中的红色那里应该和自己添加的信息一致,否则会验证失败

还有一个问题需要注意,验证信息可能会出现在控制台而没有在页面输出,解决这个问题需要在form表单中添加

<s:form validate="true">

当然,页面也需要有<s:fielderror>输出错误信息的标签

你可能感兴趣的:(struts2)