struts2中的动态方法调用(DMI)
自定义的Action一般会有很多方法,如果想调用action中的某个方法,可以在struts.xml配置文件中指定method值。(但是这种方法不推荐用,因为为每个方法都配置Action太麻烦了)。
可以使用动态方法调用会简单很多,Action只需要在配置文件中写一次即可。可以在url地址中如下调用:
http://localhost:8080/struts2_0500_DMI/hello!add(调用add方法)
http://localhost:8080/struts2_0500_DMI/hello!del(调用del方法)
如下面的配置文件所示:
method=”add”可以不用写
<struts>
<!-- Add packages here -->
<constant name="struts.devMode" value="true" />
<package name="front" namespace="/" extends="struts-default">
<action name="hello" class="net.dreamcreating.IndexAction"method="add">
<result>
/dmi.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>