码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2 Action中动态方法调用、通配符的使用

时间:2016-09-26 19:43:47      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

一、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属性中使用星号来匹配任意的字符串

技术分享

技术分享

实现效果:

技术分享

 

Struts2 Action中动态方法调用、通配符的使用

标签:

原文地址:http://www.cnblogs.com/WJ-163/p/5910016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!