zoukankan      html  css  js  c++  java
  • Struts2配置文件(动态方法调用)

    1、准备工作:

    (1)在一个action中写多个方法:

    public class HelloAction {
        public String add(){
            System.out.println("添加");
            return "success";
        }
    
        public String delete(){
            System.out.println("删除");
            return "success";
        }
    
        public String update(){
            System.out.println("修改");
            return "success";
        }
    
        public String selete(){
            System.out.println("查询");
            return "success";
        }
    }

    (2)为了配置文件的简洁明了,设置两个配置文件,主文件引入另一个配置文件:

    <struts>
        <include file="zhb/hello/struts.xml"></include>
    </struts>

    另外一个配置文件:

    <struts>
        <package name="hello" namespace="/hello" extends="struts-default">
            <action name="HelloAction_add" class="pers.zhb.hello.HelloAction" method="add">
                <result name="success">/hello.jsp</result>
            </action>
    
            <action name="HelloAction_delete" class="pers.zhb.hello.HelloAction" method="delete">
                <result name="success">/hello.jsp</result>
            </action>
    
            <action name="HelloAction_update" class="pers.zhb.hello.HelloAction" method="update">
                <result name="success">/hello.jsp</result>
            </action>
    
            <action name="HelloAction_selete" class="pers.zhb.hello.HelloAction" method="selete">
                <result name="success">/hello.jsp</result>
            </action>
        </package>
    </struts>

    这样书写起来比较麻烦。

    (3)测试结果:

     

     2、动态方法调用(方式一):

    (1)配置动态方法调用是否开启常量(默认是关闭的):

    <struts>
        <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
        <package name="hello" namespace="/hello" extends="struts-default">
            <action name="HelloAction" class="pers.zhb.hello.HelloAction">
                <result name="success">/hello.jsp</result>
            </action>
        </package>
    </struts>

    (2)访问方式:

     

     3、动态方法调用(方式二):

    (1)配置文件:

    <struts>
        <package name="hello" namespace="/hello" extends="struts-default">
            <action name="HelloAction_*" class="pers.zhb.hello.HelloAction" method="{1}">
                <result name="success">/hello.jsp</result>
            </action>
        </package>
    </struts>
    method="{1}"中的“1”可以取出“*”中的内容。
    (2)访问方式:

  • 相关阅读:
    Delphi Canvas的FillRect(const Rect: TRect) 函数的作用
    将多个jpg文件以追加形式合并成一个文件_delphi教程 bmp 合并 http://www.west.cn/www/info/58058-1.htm
    早期原版翎风(LF)引擎(M2)源码(Delphi)
    Application.Restore不起作用了
    delphi 函数isiconic 函数 判断窗口是否最小化
    delphi SetWindowPos改变窗体位置和状态
    Linux 软件看门狗 watchdog
    使用Linux C编写看门狗(watchdog)程序
    Linux编程之《看门狗进程》
    Mac PWN入门巩固篇(六)
  • 原文地址:https://www.cnblogs.com/zhai1997/p/12200501.html
Copyright © 2011-2022 走看看