struts2的DMI

struts2的请求会先找到<package>在根据<action>找到相应的Action.class!然后根据<result></result>返回的页面!有时要指定相应的方法,这时会用到DMI!

看下action.class:

package cn.keith.action;


import com.opensymphony.xwork2.ActionSupport;

public class NameSpaceTest extends ActionSupport {
	public String nameSpace() {
		System.out.println("~~~~~~~~SUCCESS~~~~~~~~~~~");
		return SUCCESS;
	}

	public String add() {
		System.out.println("~~~~~~~~~~~~~~~~~~~");
		return SUCCESS;
	}
}

 

struts.xml:

	<package name="main" extends="struts-default" namespace="/">
		<action name="index" class="cn.keith.action.NameSpaceTest">
			<result>/nameSpaceOther.jsp</result>
		</action>
	</package>
	
	<package name="dmi" extends="struts-default">
		<action name="dmi" class="cn.keith.action.NameSpaceTest">
			<result>/dmiTest.jsp</result>
		</action>
	</package>

 jsp页面:

 <body>
	<a href="dmi/dmi!add">DMI测试 </a>
  </body>

 

这时就会调用action里的add()方法,而不是另一个!

你可能感兴趣的:(jsp,xml,struts)