struts2配置文件struts.xml配置action的method无效

一新来同事看代码的时候发现struts.xml 中配置的method属性无效,

[b]struts.xml 配置如下:[/b]

<?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="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.serve.static.browserCache" value="false"/>

<package name="default" namespace="/" extends="struts-default">
<action name="custom" class="customAction" method="custom">
<result name="success">/WEB-INF/view/index.jsp</result>
<result name="custom">/WEB-INF/view/custom.jsp</result>
</action>
</package>


</struts>


[b]java代码:[/b]

public class customAction{

public String index(){
try {
System.out.println("index");

} catch (Exception e) {
e.printStackTrace();
}
return "success";
}

public String custom(){
System.out.println("custom");
return "custom";
}

}


访问URL:[url]http://localhost:6060/custom/custom![b]index[/b].do[/url],结果却能访问到index方法。
按理来说,在struts.xml中配置了struts.enable.DynamicMethodInvocation=false、method=custom,通过上面的url是访问不到index方法。

当时我也不得其解,之后查找代码终于发现问题所在。

[b]问题原因:[/b]
在Struts 2的核心jar包-struts2-core中,有一个default.properties的默认配置文件,default.properties是不能被更改的。如需要更改里面的配置信息,可以在src根目录下建一个 [b]struts.properties[/b]的配置文件,然后重写所要更改的配置信息。经查看struts.properties中中配置了struts.enable.DynamicMethodInvocation=true。

[b]结论:[/b]如果相关属性在这个文件里面设置了属性,那么在struts.xml 中再配置是无效的。

经过测试得出这个结论,还望指教。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值