struts客户端校验

服务端的数据校验测试是成功的,可是客户端的校验总是不对,参考了struts官方文档和书,调试通过了,总结一下:

1.jsp页面的s:form表单添加validate="true" 并且action中的Action路径不需要加.action

 

2.确保form表单的主题是xhtml或其他支持客户端校验的主题,默认是xhtml,实在不行就在form表单加上theme="xhtml"(主要就是看主题包下面有没有validation.js这个文件了,查看主题包在struts-core这个jar包下的template.xhtml template.simple等等文件夹。)

 

3.引用官方文档的话

A correct action and namespace attributes must be provided to the <s:form> tag. For example, if the action named "quizClient" is defined in the "/validation" namespace, the form must be configured as:

如果quizClient定义在"/validation"命名空间下,那么表单的配置必须如下:

<s:form method="post" validate="true" action="quizClient" namespace="/validation">
   <s:textfield label="Name" name="name"/>
   <s:textfield label="Age" name="age"/>
   <s:textfield label="Favorite color" name="answer"/>
   <s:submit/>
</s:form>

While the following will "work" in the sense that the form will function correctly, client-side validation will not. That is because Struts must know the exact namespace and action (rather than a URL) to properly support validation.

如何按照以下配置,那么服务端校验是正常的,客户端校验确不行,struts必须知道action确切的命名空间而不仅仅是一个URL

<s:form method="post" validate="true" action="/validation/quizClient.action">
   <s:textfield label="Name" name="name"/>
   <s:textfield label="Age" name="age"/>
   <s:textfield label="Favorite color" name="answer"/>
   <s:submit/>
</s:form>
4.校验配置的xml文件中,不要使用key的方式引用国际化资源,会报错,使用${getText("pass.requried")}的表达式的方式来引用国际化资源,能正常显示。
 
  
说明namespace必须和url分开来写,才能进行准确的客户端校验
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值