Struts2 Action中動態方法調用、通配符的使用


一、Struts2執行過程圖:


 二、struts2配置文件的加載順序

struts-default.xml---struts-plugin.xml---struts.xml

具體步驟:

 


 


 


 


 


 


 


 三、Action中動態方法調用<Dynamic Method Invocation> DMI

第一種方式:

自定義DMIAction類,使它繼承ActionSupport類,該類無需手動重寫execute(),底層有默認實現。因此我們也可以自定義方法list。

struts.xml中的action元素植入method調用前台返回的方法list

若一個類中有多個方法,在struts.xml中需植入多個action元素,因此該方法的安全性低


 

第二種方式:

 在struts.xml中開啟動態方法調用,即可使用一個action,並通過在Action的名稱中使用感嘆號(!)來標識要調用的方法名稱

 

       /*
	 * 添加圖書
	 */
	public String add() throws Exception {
		System.out.println("======add====");
		return "add";
	}
	
	
	/*
	 * 刪除圖書
	 */
	
	public String del() throws Exception {
		System.out.println("======del====");
		return "del";
	}
	
	
	/*
	 * 修改圖書
	 */
	public String edit() throws Exception {
		System.out.println("======edit====");
		return "edit";
	}

 

  

 

執行效果:


四、Action中通配符的使用

 通配符用星號(*)表示,用於配置0個或多個字符串,在配置Action時,可以在action元素的name屬性中使用星號來匹配任意的字符串

實現效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM