Struts2 通配符方法验证
我遇到的情况是,同一个操作类中有 2 个方法,即 method1 和 method2。下面是我在 struts.xml 中的操作映射
< action name="actionName_*" class="sample.input.SubmitTest" method="{1}">
< interceptor-ref name="defaultStak" />
< result name="input">info.jsp< result ends>
< result name="success">info.jsp< result ends>
< result name="error">error.jsp< result ends>
< action ends>
method1 和 method2 的验证规则不同,所以我有 2 个验证 xml 文件。 1:actionName_method1-validation.xml 2:actionName_method2-validation.xml
我从 JSP 调用这些方法,如下所示,
< s:form action="actionName_" method="post">
<!-- here goes the fields to be submitted -->
<s:submit type="simple" method="method1" value="execute1"/>
<s:submit type="simple" method="method2" value="execute2"/>
< s:form end tag>
但是由于某种原因,验证没有被执行。我在这里错过了什么吗,有人可以帮忙吗?
I have a situation where i have 2 methods in the same action class, method1 and method2. Below is my action mappings in struts.xml
< action name="actionName_*" class="sample.input.SubmitTest" method="{1}">
< interceptor-ref name="defaultStak" />
< result name="input">info.jsp< result ends>
< result name="success">info.jsp< result ends>
< result name="error">error.jsp< result ends>
< action ends>
Validation rules for method1 and method2 are different so i have 2 validation xml files. 1: actionName_method1-validation.xml
2: actionName_method2-validation.xml
This configuration is as per http://struts.apache.org/2.1.6/docs/action-configuration.html#ActionConfiguration-DynamicMethodInvocation
I invoke these methods from a JSP as shown below,
< s:form action="actionName_" method="post">
<!-- here goes the fields to be submitted -->
<s:submit type="simple" method="method1" value="execute1"/>
<s:submit type="simple" method="method2" value="execute2"/>
< s:form end tag>
However for some reason the validations are not getting executed. Am I missing something here, can anyone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误出现在 s:submit 中,下面是正确的 s:submit ,它有效
The mistake was in the s:submit, below is the correct s:submit which worked
我一直在寻找这个问题的答案,但这里出现的答案并不能解决我的问题。
要解决该问题,您必须应用 @Rajesh 解决方案(在
标记中使用action
属性而不是method
)并且您必须重命名验证文件,以便它满足以下规则:因此,在这种情况下,验证文件应重命名为:
因为操作类是提交测试。
我希望这个答案可以帮助其他人解决使用通配符方法进行 XML 验证的问题。
I was looking for an answer to this question, but the one that appeared here wasn't solving my problem.
To solve the problem, you have to apply the @Rajesh solution (use
action
attributes instead ofmethod
in the<s:submit>
tag) and you have to rename the validation file so that it fulfills the following rule:So the validation files, in this case, should be renamed to:
as the action class is SubmitTest.
I hope this answer can help others with the problem of XML validation with wildcard methods.