struts2DMI(动态方法调用)

  DMI(Dynamic Method Invoke)即动态,是strus2的一个特性,我们知道,在最开始学习strus2时,往往一个action中只有一个excute方法,比如说add,delete,update,search,往往要在struts.xml中配置配置多个<action>以便指定不同的method,但是strus2目前提供了DMI机制,即如下配置即可:

  <action name="book" class="com.speed.BookAction">

  <result>/index.jsp</result>

  </action>

  而访问时,只需如下访问便可实现一个action.java中配置多个方法:

  <body>

    <a href="book!addBook.action">添加图书信息</a><br />

    <a href="book!delBook.action">删除图书信息</a><br />

    <a href="book!updateBook.action">修改图书信息</a><br />

    <a href="book!readBook.action">查询图书信息</a><br />

   </body>

 其中,book对应<action>的name,addBook是action中的方法名,统一格式为:actionName!methodName

 但要注意:有些struts的版本中动态方法调用时默认关闭的,要显式打开,

 在struts.xml中添加<constant name="struts.enable.DynamicMethodInvocation" value="true" /> ,打开动态方法调用。

时间: 2024-08-28 18:25:40

struts2DMI(动态方法调用)的相关文章

Struts2学习第七课 动态方法调用

动态方法调用:通过url动态调用Action中的方法. action声明: <package name="struts-app2" namespace="/" extends="struts-default"> <action name="Product" class="org.simpleit.app.Product"> </package> URI: --/strut

动态方法调用

1.先建立一个项目 2.在此项目中需要建立两个jsp 1)在第一个jsp中写入一句话 <body> User Add Success! </body> 2)在第二个jsp中写入链接 <body> Action执行的时候并不一定要执行execute方法<br /> 可以在配置文件中配置Action的时候用method=来指定执行哪个方法 也可以在url地址中动态指定(动态方法调用DMI)(推荐)<br /> <a href="<

struts2中通配符和DMI(动态方法调用)

在struts2中不建议使用Dynamic Method Invocation,具体原因见官方文档: http://struts.apache.org/docs/action-configuration.html#ActionConfiguration-WildcardMethod; 刚刚接触这块,所以两种方法各自实现一下: 1)动态方法调用: struts.xml文件: <package name="default" namespace="/yin" ext

Struts2动态方法调用(DMI)

在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多 第一种方式:指定method属性这种方式我们前面已经用到过,类似下面的配置就可以实现 <action name="chainAction" class="chapter2.action.Chapter2Action" method="chainAction"> <result name="chai

C#动态方法调用

此篇将介绍C#如何在运行时动态调用方法.当某些类型是运行时动态确定时,编译时的静态编码是无法解决这些动态对象或类的方法调用的.此篇则给你一把利剑,让动态对象的方法调用成为可能. 1.动态调用dll里的方法: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

struts2.5动态方法调用和默认Action

在动态方法调用中,使用通配符方法出现问题,参考了http://www.cnblogs.com/jasonlixuetao/p/5933671.html 这篇博客,问题解决了. 这个是helloworld.xml: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Co

ActionMethod_DMI_动态方法调用

Action执行的时候并不一定要执行execute方法可以在配置文件中配置Action的时候用method=来指定执行那个方法,也可以在url地址中动态指定(动态方法调用DMI)(推荐) 动态方法调用的配置要先打开: 1 <constant name="struts.enable.DynamicMethodInvocation" value="true"/> index.jsp 1 <%@ page language="java"

Struts2系列:(7)通配符和动态方法调用

当前存在的问题:在struts.xml配置文件中,每个action标签对应一个类中的方法.但是,在实际JavaWeb项目开发中,有许多继承自ActionSupport类的类(其中也包括很多方法),如果每个方法对应一个action标签,那么就会造成struts.xml非常庞大. 本节中介绍的通配符 和 动态方法调用 就是为了解决这一问题.本节分成2个部分:(1)通配符映射 和 (2)动态调用 概念:Struts应用可能有很多action 声明,可把多个相似的映射关系简化为一个(通用)映射关系的机制

struts.enable.DynamicMethodInvocation = true 动态方法调用

default.properties 在Struts 2的核心jar包-struts2-core中,有一个default.properties的默认配置文件.里面配置了一些全局的信息,比如: struts.enable.DynamicMethodInvocation = true,-动态方法调用,为true时,就可以在struts.xml配置“*”的通配符,来调用action里的方法(下面介绍) struts.action.extension=action,-action 的后缀名,可以改成.t