前言:在struts2.5中添加了新的标签allowed-methods
<?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">
<!--第1种最直接的 -->
<struts>
<package name="a" extends="struts-default" namespace="/">
<action name="hello" class="com.HelloWorld">
<result name=""></result>
</action>
</package>
</struts>
<?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">
<!--第2种使用通配符实现在新版本中需要在result后添加 allowed-method标签 -->
<struts>
<package name="a" extends="struts-default" namespace="/">
<action name="hello_*" class="com.HelloWorld" method="{1}">
<result name=""></result>
<!--allowed-methods中直接写方法名,多个方法用逗号隔开 -->
<allowed-methods>add,update</allowed-methods>
</action>
</package>
</struts>
<?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">
<!--第3种动态访问 -->
<!-- 需要配置constant,name属性:struts.enable.DynamicMethodInvocation,具体查看default.properties-->
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<package name="a" extends="struts-default" namespace="/">
<action name="hello" class="com.HelloWorld" >
<result name=""></result>
<allowed-methods>add,update</allowed-methods>
</action>
</package>
</struts>