struts2.3.15.3中动态方法调用默认是关闭的

时间:2021-11-12 08:56:51

  初学ssh,用的struts2.3.15.3,使用了如下表单:

    <form action="/spring3/index/login.action" method="post">
<input type="hidden" name="method:login"/>
用户名:<input name="username"/><br/>
密码:<input name="password"/><br/>
<input type="submit" value="登录"/>
</form>

  但是运行的时总是报java.lang.NoSuchMethodException: com.fallsleep.action.LoginAction.execute()错误,由于是跟着视频慢慢做的(视频中用的struts2.3.4),所以十分不能理解为什么会出这个错误。百度了半天NoSuchMethodException和execute(),搜到一堆完全不相关的错误,直到看到http://zhidao.baidu.com/link?url=isKUfiqdIcS9CJ_oqR8yRw1s08FXS8Xkvex9ZhptR4kvET2OX6b5nrmiEAOd84Y-AlvbEIHCJO0Q_PhGEBTPxa,才意识到可能是动态方法调用的问题。

  于是便百度了下“struts 动态方法调用”,并查看struts2-core-2.3.15.3.jar,在org.apache.struts2包下的default.properties文件中发现,108行为struts.enable.DynamicMethodInvocation = false,证明动态方法调用确实是关闭的。

  在struts的配置文件中加入<constant name="struts.enable.DynamicMethodInvocation" value="true" />,开启动态方法调用后程序正常运行了。