下面是struts.xml的部分内容
<!-- 打开开发模式,便于在改动内容后迅速反馈,而不需要重启服务器。默认是关闭的-->
<constant name="struts.devMode" value="true" />
<!-- 支持动态方法调用,默认是关闭的。好处在于可以在浏览器中以“!methodname”的方式动态的调用Action中的方法-->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<package name="action" namespace="/path" extends="struts-default">
<action name="hello" class="action.MyAction" method="method1">
<result name="success">
/hello.jsp
</result>
</action>
<action name="Hello" class="action.MyAction">
<result name="success">
/hello.jsp
</result>
</action>
</package>
MyAction中的内容
public class MyAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
public String method1(){
return SUCCESS;
}
}
在浏览器中输入:http://localhost:8080/struts2/path/hello。
然后再输入:http://localhost:8080/struts2/path/Hello!method1。(DMI)
两者都能正常访问。