---
title: "struts2动态方法调用"
author: "zhaosoft"
date: "2008-10-24T19:46:31Z"
tags: []
slug: "struts2"
draft: false
lastmod: "2008-10-24T19:46:31Z"
id: 257706
url: "https://zhaosoft.iteye.com/blog/257706"
---

struts2动态方法调用  
  struts2中无需配置就可以直接调用Action中非execute方法的方式，就是试用struts2的动态动态方法调用。  
动态方法调用(Dynamic method Invoc)是在action的名字中使用感叹号(!)来标示要调用的方法名，其语法格式为  
  actionName!methodname.action  
 例如我们的配置如下：  
&lt;action name="login" class="com.pj.action.LoginAction" &gt;  
&lt;result type="json"&gt;&lt;/result&gt;  
&lt;/action&gt;    
当请求/login!query.action时,将调用LoginAction的query()方法，当请求/login!save.action时，将调用LoginAction的save()方法。  
strust2提供了一种配置，用于禁用DMI,你可以在struts.xml文件中，使用constant元素将struts.enable.DynamicMethodInvocation属性设置为false，来关闭DMI。