zoukankan      html  css  js  c++  java
  • OGNL表达式

    所有类及struts.xml配置:

    1,访问值栈中的action中的普通属性: 

    在index.jsp里:访问属性<a href="ognl.action?username=u&password=p">ognl</a>直接传到相应的action里,定义username和password,生成get、set方法,2个属性将自动保存在值栈里,在返回页面直接用<s:property value="username"/>标签取得相应属性。

    2,访问值栈中 对象的普通属性(get、set方法):在index.jsp里的表单提交姓名,密码

    <form action="ognl.action" method="post">
           Name:<input type="text" name="user.name"/>
           Age:<input type="text" name="user.age"/>
           <input type="submit" value="Submit"/>
       </form>

    提交到UserAction,在UserAction里定义User类生成get、set方法,在返回页面就可以访问他的get方法取到属性:通过<s:property value="user.name"/>标签,

    3,访问值栈中 对象的普通方法:Cat类,

    public String miao(){
    return "miao";
    }
    
    public static int leg(){
    return 4;
    }

    还有name的带参构造,在UserAction里定义cat,生成get、set,index.jsp里传进去cat.name,会自动生成Cat对象,用标签<s:property value="cat.miao()"/>就能访问她的普通方法miao。和他的静态方法leg(),也用<s:property value="cat.leg()"/>标签。此标签也可以访问Action里的普通方法,和静态方法(Action里定义了fun()和fun2()返回250和500)。

    访问普通类的静态方法:@包名.类名@方法名(),访问静态属性:@包名.类名@属性名

    访问静态方法:<s:property value="@com.oracle.ognl.action.C@ccc()"/>
    访问静态属性:<s:property value="@com.oracle.ognl.action.C@sex"/>

    访问Math类的静态方法:
    访问Math类的静态方法<s:property value="@@max(10,100)"/>

  • 相关阅读:
    欧拉公式
    isap的一些想法
    错误合集
    Hello World
    PAT (Advanced Level) Practice 1068 Find More Coins
    PAT (Advanced Level) 1087 All Roads Lead to Rome
    PAT (Advanced Level) 1075 PAT Judge
    PAT (Advanced Level) 1067 Sort with Swap(0, i)
    PAT (Advanced Level) 1017 Queueing at Bank
    PAT (Advanced Level) 1025 PAT Ranking
  • 原文地址:https://www.cnblogs.com/lihaoyang/p/4833903.html
Copyright © 2011-2022 走看看