验证特定动作映射的方法 [英] Validate method for a specific action mapping
问题描述
我的 struts 2 xml 文件中有 2 个动作映射,它们映射到以下相同动作类的 2 个方法
I have 2 action mapping in my struts 2 xml file that map to 2 methods of the same action class as below
<action name="action1" class="com.web.action.MyAction method="myMethod1">
<result>success1.jsp</result>
</action>
<action name="action2" class="com.web.action.MyAction method="myMethod2">
<result>success2.jsp</result>
</action>
我还覆盖了 ActionSupport 类的 validate() 方法.现在我希望这个验证方法应该只对 action1 执行,而不是对 action2 执行.有没有办法这样做?我知道我可以将这两种方法放在单独的操作类中,这会起作用.
I have also overridden the validate() method of the ActionSupport class. Now I want that this validate method should execute only for action1 and NOT fro action2. Is there is way to do so? I know i can put the 2 methods in seperate action classes and this will work.
推荐答案
验证"拦截器使用与准备"拦截器相同的带前缀的方法实用程序.
The "validation" interceptor uses the same prefixed method utility as the "prepare" interceptor.
验证"拦截器将调用特定于方法的验证方法;对于您的具体示例:
The "validation" interceptor will call method-specific validation methods; for your specific example:
public void validateMyMethod1() { ... }
public void validateMyMethod2() { ... }
请参阅 "validation" 拦截器文档,但对于更好/更详细,准备"拦截器文档.
See the "validation" interceptor docs, but for better/more detail, the "prepare" interceptor docs.
这篇关于验证特定动作映射的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!