Struts2动态调用DMI及错误解决方法

在Strust2中action可以定义自己的方法,调用方法有两种方式,一种方式是struts.xml中指定method来表示需要用到的方法,但是这种方法缺点在于如果你的Action中有很多方法则要多次配置,这样很繁琐,另一种方法是使用动态方法调用DMI。

举一个简单的例子——

比如LoginAction中有add,dell方法,则

1、配置struts.xml文件

1 2     
3            /add.jsp
4            /dell.jsp
5     

6

2、在 loginAction中 编写add方法和dell方法:

public  String  add()
{
  return “add”;
}
public  String dell()
{
  return “dell”;
}

3、链接中使用!动态调用所需方法:

调用add方法
调用dell方法

常见错误:

 There is no Action mapped for namespace [/XXX] and action name [xxx!xxx] associated with context path [/xxx_method]. 

解决方法:

 默认的Struts.xml中是这样的

 这样我们在地址栏输入感叹号动态调用方法的时候会出错,我们只需更改这一句即可

 

  

struts2文件上传(保存为BLOB格式) http://www.linuxidc.com/Linux/2014-06/102905.htm

Struts2的入门实例 http://www.linuxidc.com/Linux/2013-05/84618.htm

Struts2实现ModelDriven接口 http://www.linuxidc.com/Linux/2014-04/99466.htm

遇到的Struts2文件下载乱码问题 http://www.linuxidc.com/Linux/2014-03/98990.htm

Struts2整合Spring方法及原理 http://www.linuxidc.com/Linux/2013-12/93692.htm

Struts2 注解模式的几个知识点 http://www.linuxidc.com/Linux/2013-06/85830.htm

Struts 的详细介绍请点这里
Struts 的下载地址请点这里