struts2

调用动态方法的3中方法

  I:可以通过在action属性指定方法调用

 II:官方推荐使用 

  <action name="userLogin_*" class="com.wangsl.action.UserAction" method="{1}"> 红色标识是一一对应的,可以给予请求url直接指定方法名,

<result name="success">/default.jsp</result>

</action>

的形式,需要在 <constant name="struts.enable.DynamicMethodInvocation" value="false"/>配置一下即可,

在struts 2.5版本中会报 **not allowanced的错误,

只需要在action同级目录中添加

<global-allowed-methods>regex:.*</global-allowed-methods>即可.

III: 另外一种方法不推荐使用,请求url形如 http://localhost:8080/项目名/命名空间/actionName!方法名的形式,但是需要配置

<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

,如果匹配不到namespace及action,也需要配置一下<global-allowed-methods>regex:.*</global-allowed-methods>即可.

posted @ 2017-03-17 17:50  虚竹一梦  阅读(173)  评论(0编辑  收藏  举报