struts2.5动态方法绑定问题

来源:互联网 发布:剑三重置版优化补丁 编辑:程序博客网 时间:2024/06/14 16:32

Struts动态方法绑定不成功,Struts2.5动态方法调用失败升级问题
今天发现Struts2.5版本的不能使用动态方法绑定 查了下说是调用实体类action时不安全,新版本中默认关闭了
在Struts.xml中配置了开启还是不能使用
文件如下

<?xml version="1.0" encoding="UTF-8" ?>    <!DOCTYPE struts PUBLIC        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"        "http://struts.apache.org/dtds/struts-2.0.dtd">    <struts>     <!--  <constant name="struts.enable.DynamicMethodInvocation" value="true" />   -->   <constant name="struts.objectFactory" value="spring"></constant>    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>  <package name="default" extends="struts-default"   namespace="/">    <action name="hello" class="com.maobo.action.LoginAction">      <result name="ok">/WEB-INF/page/success.jsp</result>              <result name="error">/WEB-INF/page/error.jsp</result>      </action>     <action name="hi" class="com.maobo.action.LoginAction" method="hi">      <result name="ok">/WEB-INF/page/success.jsp</result>              <result name="error">/WEB-INF/page/error.jsp</result>      </action>   <action name="m_*" class="com.maobo.action.LoginAction" method="{1}">      <result name="ok">/WEB-INF/page/success.jsp</result>              <result name="error">/WEB-INF/page/error.jsp</result>      </action>  </package>  </struts>  

执行
http://127.0.0.1/MVS/m_hi 返回

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [m_hi] associated with context path [/MVS].

MVS WEB项目工程名

不知为何? 开关已经打开了的

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

参考资料:
http://blog.csdn.net/achilles12345/article/details/37697457
http://zhidao.baidu.com/link?url=Og-hTpiYl1pUGRnZEy6F9ijXFxC9quYNdg-jLKe9l9BMBeM2yh6wVexZwHggIcumLe4I8RgFl2f9ZgU2DVp0ps29xZAL4OKyQH8ns2t1NkW
这篇里说action里加 *
加上后配置文件泛红报错

官方配置文件
http://struts.apache.org/docs/action-configuration.html
http://www.brucephillips.name/blog/index.cfm/2011/2/19/Struts-2-Security-Vulnerability–Dynamic-Method-Invocation

http://blog.csdn.net/javaalpha/article/details/8855368
此篇文章说通配符要把属性设为false ???

这篇算是解决了问题
http://ask.csdn.net/questions/260958

总结一下
2.5版本是要打开开关不错。配置文件之所以报错的原因是因为头信息中版本号不对!复制了官方的头信息后泛红报错的地方会消失。
完整配置文件如下
官方参考

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"        "http://struts.apache.org/dtds/struts-2.5.dtd"><struts>    <constant name="struts.objectFactory" value="spring"></constant>    <constant name="struts.enable.DynamicMethodInvocation" value="true" />    <package name="default" extends="struts-default" namespace="/">    <!-- 关键地方  struts2.5 为了提升安全性,添加了 allomethod 这么个玩意-->     <global-allowed-methods>regex:.*</global-allowed-methods>        <action name="login*" class="com.maobo.action.LoginAction" method="{1}">            <result name="ok">/WEB-INF/page/success.jsp</result>            <result name="error">/WEB-INF/page/error.jsp</result>        </action>    </package></struts>  

注意头部信息中

<!DOCTYPE struts PUBLIC        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"        "http://struts.apache.org/dtds/struts-2.5.dtd"><struts>

版本号应为 struts-2.5.dtd
关键地方 struts2.5 为了提升安全性,添加了 allomethod 这么个玩意

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

具体请参考文章不再细述
http://ask.csdn.net/questions/260958

2 0
原创粉丝点击