• 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()方法。






  • 相关阅读:
    CSS&JS两种方式实现手风琴式折叠菜单
    MySQL创建数据库/表等基本命令操作
    web注册功能实现
    符合altium designer操作习惯的cadence快捷键设置
    运行Capture.exe找不到cdn_sfl401as.dll
    modelsim遇到的问题(更新)
    1.4 扩展
    1.3 Security
    1.2 Install Extension 安装扩展
    1.1 Modify Template修改模板
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8334545.html
Copyright © 2020-2023  润新知