Struts2中DMI(动态方法调用)的一些问题
2014-02-19 22:42
357 查看
<package name="front" namespace="/front" extends="struts-default">
<default-action-ref name="index" />
<action name="helloword" class="struts.IndexAction">
<result name="add">
/hello.jsp
</result>
<result name="love">
/love.jsp
</result>
</action>
</package>
大家看上面程序,指定了action的class="struts.IndexAction“
再来看IndexAction类
package struts;
import com.opensymphony.xwork2.ActionSupport;
public class IndexAction extends ActionSupport{
public String add(){
return "add";
}
public String love(){
return "love";
}
}
里面并没有excute()方法,这时大家给以这样配置<action name="helloword" class="struts.IndexAction" method="add">就可以返回IndexAction类中add方法的值,
但是这种方法不推荐!推荐的方法是动态调用,也就是DMI.
比如在地址栏中输入URL:http://localhost:8080/struts2/front/helloword!add
但是:如果这样输入的话,会报错(There is no Action mapped for namespace [/front] and action name [helloword!add()] associated with context path [/Struts2_10003].)
因为:struts2中默认不允许使用DMI
所以:需要在配置文件中打开: <constant name="struts.enable.DynamicMethodInvocation" value="true"/>这样大家在地址栏动态输入就可以得到预期的页面
<default-action-ref name="index" />
<action name="helloword" class="struts.IndexAction">
<result name="add">
/hello.jsp
</result>
<result name="love">
/love.jsp
</result>
</action>
</package>
大家看上面程序,指定了action的class="struts.IndexAction“
再来看IndexAction类
package struts;
import com.opensymphony.xwork2.ActionSupport;
public class IndexAction extends ActionSupport{
public String add(){
return "add";
}
public String love(){
return "love";
}
}
里面并没有excute()方法,这时大家给以这样配置<action name="helloword" class="struts.IndexAction" method="add">就可以返回IndexAction类中add方法的值,
但是这种方法不推荐!推荐的方法是动态调用,也就是DMI.
比如在地址栏中输入URL:http://localhost:8080/struts2/front/helloword!add
但是:如果这样输入的话,会报错(There is no Action mapped for namespace [/front] and action name [helloword!add()] associated with context path [/Struts2_10003].)
因为:struts2中默认不允许使用DMI
所以:需要在配置文件中打开: <constant name="struts.enable.DynamicMethodInvocation" value="true"/>这样大家在地址栏动态输入就可以得到预期的页面
相关文章推荐
- Struts2中(动态方法调用)DMI的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中DMI(动态方法调用)的一些问题 4000
- Struts2服务在开启动态方法调用(DMI)的情况下,导致的安全问题,一则新闻
- Struts2中DMI(动态方法调用)的错误问题(There is no Action mapped for namespace [/xxx] and action name [xxx!yyy] a)
- Struts2自定义Action,自定义方法,DMI(动态方法调用),路径问题
- 使用Struts2动态方法调用时(DMI)出现There is no Action mapped for namespace [/user] and action name [user!add] 问题
- Struts2动态方法调用(DMI)小问题
- 关于Struts2 namespace 的学习笔记(DMI动态方法调用)
- struts2:多业务方法的处理(动态调用,DMI)
- struts2——动态方法调用(dmi)!!!
- 升级Struts2.5后使用DMI动态方法调用遇到问题
- Struts2基础之四:动态方法调用(DMI)和action通配符
- Struts2 学习 第5part 动态方法调用DMI
- Struts2 ActionMethod DMI(动态方法调用)
- Struts2中使用DMI(动态方法调用)
- struts2动态方法调用 无效问题
- Struts2-动态方法调用(DMI)