zoukankan      html  css  js  c++  java
  • struts2_7_Action类中方法的动态调用

    (一)直接调用方法(不推荐使用)

    1Action类:

    private String savePath;
    
    	public String getSavePath() {
    		return savePath;
    	}
    
    	public void setSavePath(String savePath) {
    		this.savePath = savePath;
    	}
    
    	public String other() {
    		savePath = "other";
    		return "success";
    	}
    
    	public String execute() {
    		savePath = "execute";
    		return "success";
    }

    2struts.xml文件的配置:

    <struts>
    	<package name="package" namespace="/test" 
      extends="struts-default">
    		<action name="emp" class="struts.employeeAction" 
      method="execute">
    			<result name="success">/index.jsp</result>
    		</action>
    	</package>
    </struts>

    当输入:http://localhost:8080/Struts_3/test/emp.action

    时会输出:execute 即调用execute()方法;

    当输入:http://localhost:8080/Struts_3/test/emp!other.action

    时会输出:other 即调用other()方法。

    (二)使用通配符(推荐使用)

    1)Aciton类与(一)中的同样

    2)struts.xml文件的配置:

    <struts>
    	<package name="package" namespace="/test" 			
      extends="struts-default">
    		<action name="emp*" class="struts.employeeAction" 
      method="{1}">
    			<result name="success">/index.jsp</result>
    		</action>
    	</package>
    </struts>

    訪问路径:http://localhost:8080/Struts_3/test/empexecute

    这时会输出:execute 即调用execute()方法;

    訪问路径:http://localhost:8080/Struts_3/test/empother

    这时会输出:other 即调用other()方法。






  • 相关阅读:
    MySQL 中now()时间戳用法
    ajax local.href不跳转的原因之一
    Call to a member function select() on string错误
    TP框架中ajax post请求时提示404
    TP框架中field查询字段
    jQuery如何获得select选中的值?input单选radio选中的值
    TP框架中session操作
    InnerHtml() 与html( )的区别
    C++开源项目等收集
    RCU-数据库初始化参数
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8334545.html
Copyright © 2011-2022 走看看