zoukankan      html  css  js  c++  java
  • 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属性中使用星号来匹配任意的字符串

    实现效果:

  • 相关阅读:
    用例要素(非原创)
    边界接口设计
    项目管理平台架构
    内外网邮件自动转发
    Python技术公众号100天了
    将博客搬至CSDN
    Android项目真的要去做混淆(加密)处理
    【转】Android Gson的使用
    【转】在eclipse上使用Git
    在AChartEngine上绘图,手指标记当前位置
  • 原文地址:https://www.cnblogs.com/WJ-163/p/5910016.html
Copyright © 2011-2022 走看看