zoukankan      html  css  js  c++  java
  • 关于Struts2中param的作用

    1、页面传参与配置传参的区别:
      如果页面Form表单的参数在Action类中有相应的setter方法,则会优先取页面Form表单传过来的值,如果页面没有该属性同名的参数,则会从配置文件中取同名的参数值作为它的默认值
    2、Action中调用配置的变量,只需要该参数的setter方法即可,不需手动写代码,Struts2默认会同名赋值。
    例:

    jsp页面

    <form name="fm" action="paramTest.action" method="post">
    <input type="text" name="username" value="wjlvivid">
    <input type="text" name="password" value="123456">
    <input type="submit" value="提交">
    </form>


    Action类 ParamTestAction.java

    private String username;
    private String password;
    //相应的setter、getter方法.....
    public String paramTest(){
    System.out.println("username:"+username+" password:"+password);
    return "success";
    }


    配置文件:

    <action name="paramTest" class="com.sino.ParamTestAction" method="paramTest">
        <param name="username">wjl</param>
        <param name="password">000000</param>
        <result name="success">/menu/menu.jsp</result>
    </action>


    请求一下该action,可发现输出的值为:
      username:wjlvivid password:123456
    如果把<input type="text" name="password" value="123456">去掉,则输出 配置的参数值
      username:wjlvivid password:000000

    <param>的作用就是为Action中的某些属性赋一个默认值,通常这样做的如配置路径、文件名之类的....

    这样就明白了。。

    例如:

    全局结果:

            <global-results>
                <result name="success" type="json">
                    <param name="root">response</param>
                </result>
            </global-results>

    action配置:

            <action name="trainacontentType_*" method="{1}" class="traincontentTypeAction">
                <param name="savePath">G:/images/videos/</param>
                <result name="toAdd">/view/train/addTrainFile.jsp</result>
            </action>
  • 相关阅读:
    前端工程精粹(一):静态资源版本更新与缓存
    METADATATYPE的使用,MVC的MODEL层数据验证
    Android开发之Intent.Action
    Android应用开发SharedPreferences存储数据的使用方法
    php开发环境搭建 win 7 + apache + mysql
    windows 2003 导出excel iis 配置记录
    fineui demo地址
    Fourth
    Third
    Second
  • 原文地址:https://www.cnblogs.com/qlqwjy/p/8529440.html
Copyright © 2011-2022 走看看