【问题标题】:Dynamic Method invocation in Struts2Struts2 中的动态方法调用
【发布时间】:2012-03-05 07:14:22
【问题描述】:

问题陈述

Jsp
<s:a href="newUser.action" > New User SignIn</s:a>

Struts.xml
<action name="*User"  method="{1}" class="action.NewUser">
<result name="populate">/jsp/registerUser.jsp</result>
<result name="success">/jsp/success.jsp</result>            
</action> 

Action Class has the method 
populate(){

}

我想使用 STRUTS2 的动态方法调用工具。通常,框架将 * 字替换为 struts.xml 文件的方法属性。 有没有办法可以使用不同的方法名称。在我的情况下,框架将方法名称 new() 附加到 struts.xml 文件,但我的操作类中有一个名为 populate() 的方法。

【问题讨论】:

  • 这是通配符映射工作的标准方式。

标签: struts2


【解决方案1】:

您可以尝试为此使用Preparable interface and Prepare interceptor。如果您的 Action 类实现了 Preparable 并提供了一种称为 prepare() 的方法,那么它将始终在执行任何操作方法之前调用。

【讨论】:

    【解决方案2】:

    无法在newUser.action 上调用填充方法。您只需调用 populateUser.action 即可调用填充方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-07
      • 1970-01-01
      • 2012-01-22
      • 2013-07-01
      • 1970-01-01
      • 2016-01-20
      相关资源
      最近更新 更多