Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Struts2动态调用DMI及错误解决方法

在Strust2中action可以定义自己的方法,调用方法有两种方式,一种方式是struts.xml中指定method来表示需要用到的方法,但是这种方法缺点在于如果你的Action中有很多方法则要多次配置,这样很繁琐,另一种方法是使用动态方法调用DMI。举一个简单的例子——比如LoginAction中有add,dell方法,则1、配置struts.xml文件1 <package name="default"  extends="struts-default">
2      <action name="login"  class="com.action.loginAction">
3            <result name="add">/add.jsp</result>
4            <result name="dell">/dell.jsp</result>
5      </action>
6 </package>2、在 loginAction中 编写add方法和dell方法:public  String  add()
{
  return "add";
}
public  String dell()
{
  return "dell";
}3、链接中使用!动态调用所需方法:<a  href="login!add">调用add方法</a>
<a  href="login!dell">调用dell方法</a>
常见错误: There is no Action mapped for namespace [/XXX] and action name [xxx!xxx] associated with context path [/xxx_method]. 解决方法: 默认的Struts.xml中是这样的<constant name="struts.enable.DynamicMethodInvocation" value="false" /> 这样我们在地址栏输入感叹号动态调用方法的时候会出错,我们只需更改这一句即可  <!-- 打开Struts的DMI --> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> struts2文件上传(保存为BLOB格式) http://www.linuxidc.com/Linux/2014-06/102905.htmStruts2的入门实例 http://www.linuxidc.com/Linux/2013-05/84618.htmStruts2实现ModelDriven接口 http://www.linuxidc.com/Linux/2014-04/99466.htm遇到的Struts2文件下载乱码问题 http://www.linuxidc.com/Linux/2014-03/98990.htmStruts2整合Spring方法及原理 http://www.linuxidc.com/Linux/2013-12/93692.htmStruts2 注解模式的几个知识点 http://www.linuxidc.com/Linux/2013-06/85830.htmStruts 的详细介绍:请点这里
Struts 的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/116686.htm