用到的类有:

相应代码:

public class Dog {
private String name; public Dog(){ }
public Dog(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() { return "dog"+name;
} }
public class Cat {

    private Dog friend;
private String name; public Cat(){} public Cat(String name) { this.name = name;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} private int age; public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
} public Dog getFriend() {
return friend;
} public void setFriend(Dog friend) {
this.friend = friend;
} public String miao(){
return "miao";
} public static int leg(){
return 4;
} }
public class User {

    private String name;
private int age; public User(String name, int age) { this.name = name;
this.age = age;
} public User(){ } public User(int age){
this.age = age;
} public String getName() {
return name;
}
@Override
public String toString() { return "user"+age;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
} }
public class UserAction extends ActionSupport{

    /*private  String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}*/ private User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} private Cat cat; public Cat getCat() {
return cat;
} public void setCat(Cat cat) {
this.cat = cat;
} private List<User> users = new ArrayList<User>();
private Set<Dog> dogs = new HashSet<Dog>();
private Map<String,Dog> dogMap = new HashMap<String,Dog>();
private Cat[] cats = new Cat[5];
public Cat[] getCats() {
return cats;
}
public void setCats(Cat[] cats) {
this.cats = cats;
}
public List<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
this.users = users;
}
public Set<Dog> getDogs() {
return dogs;
}
public void setDogs(Set<Dog> dogs) {
this.dogs = dogs;
}
public Map<String, Dog> getDogMap() {
return dogMap;
}
public void setDogMap(Map<String, Dog> dogMap) {
this.dogMap = dogMap;
} public UserAction(){ cats[0] = new Cat("cat1");
cats[1] = new Cat("cat2");
cats[2] = new Cat("cat3"); users.add(new User(1));
users.add(new User(2));
users.add(new User(3)); dogs.add(new Dog("dog1"));
dogs.add(new Dog("dog2"));
dogs.add(new Dog("dog3")); dogMap.put("dog1", new Dog("101"));
dogMap.put("dog2", new Dog("102"));
dogMap.put("dog3", new Dog("103"));
}
public String execute() throws Exception { return SUCCESS;
}
/*public int fun(){
return 250;
}
public static int fun2(){
return 500;
}*/ }

在UserAction里new  几个Map、Set、List,生成相应的get、set方法。

对应的ognl的html代码:

  <body>
<ol>
<li>访问值栈中的action中的普通属性:username=:<s:property value="username"/></li>
<li>访问值栈中 对象的普通属性(get、set方法)<s:property value="user.name"/></li>
<li>访问值栈中 对象的普通属性(get、set方法)<s:property value="cat.friend.name"/></li>
<li>访问值栈中 对象的普通方法<s:property value="cat.miao()"/></li>
<li>访问值栈中 对象的普通方法<s:property value="cat.leg()"/></li>
<li>访问值栈中 action的普通方法<s:property value="fun()"/></li>
<li>访问值栈中 action的静态方法<s:property value="fun2()"/></li>
<hr>
<li>访问静态方法:<s:property value="@com.oracle.ognl.action.C@ccc()"/></li>
<li>访问静态属性:<s:property value="@com.oracle.ognl.action.C@sex"/></li>
<li>访问Math类的静态方法<s:property value="@@max(10,100)"/></li>
<li>访问普通类的构造方法<s:property value="new com.oracle.action.Cat('sdf')"/></li>
<hr>
<li>访问数组元素:<s:property value="cats"/></li>
<li>访问List:<s:property value="users"/></li>
<li>访问List中的某个元素:<s:property value="users[0]"/> <li>访问List中元素某个属性的集合:<s:property value="users.{age}"/></li>
<li>访问List中元素某个属性的集合中的特定值:<s:property value="users.{age}[0]"/>||<s:property value="users[0].age"/></li>
<li>访问Set:<s:property value="dogs"/></li>
<li>访问Set中某个元素(娶不到,set是无序的):<s:property value="dogs[1]"/></li>
<li>访问Map(很少一次取出来完):<s:property value="dogMap"/></li>
<li>访问Map中的某个元素:<s:property value="dogMap.dog1"/>||<s:property value="dogMap['dog1']"/>||<s:property value="dogMap[\"dog1\"]"/></li>
<li>访问Map中所有的key:<s:property value="dogMap.keys"/></li>
<li>访问Map中所有的value:<s:property value="dogMap.values"/></li>
<li>访问容器的大小:<s:property value="dogMap.size()"/>||<s:property value="users.size"/></li> </ol>
<s:debug></s:debug>
</body>

效果:

OGNL取Map,List,Set的值的更多相关文章

  1. EL表达式取Map,List值的总结

    EL表达式取Map中的值:后台action 中: Map map = new HashMap(); map.put(key1,value1); map.put(key2,value2); map.pu ...

  2. Jquery操作select,左右移动,双击移动 取到所有option的值

    $(function () { function MoveItem(fromId, toId) { $("#" + fromId + " option:selected& ...

  3. jsp页面使用el 按key获取map中的对应值

    jsp页面使用el 按key获取map中的对应值 转自:<jsp页面使用el 按key获取map中的对应值>地址:http://blog.csdn.net/baple/article/de ...

  4. map.keySet()获取map全部的key值

    map.keySet()获取map全部的key值   public static String getUrlWithQueryString(String url, Map<String, Str ...

  5. 【Java必修课】通过Value获取Map中的键值Key的四种方法

    1 简介 我们都知道Map是存放键值对<Key,Value>的容器,知道了Key值,使用方法Map.get(key)能快速获取Value值.然而,有的时候我们需要反过来获取,知道Value ...

  6. 通过Value获取Map中的键值Key的四种方法

    1 简介 我们都知道Map是存放键值对<Key,Value>的容器,知道了Key值,使用方法Map.get(key)能快速获取Value值.然而,有的时候我们需要反过来获取,知道Value ...

  7. Map:containsKey、containsValue 获取Map集合的键值的 值

    get(Object key) 返回与指定键关联的值: containsKey(Object key) 如果Map包含指定键的隐射,则返回true: containsValue(Object valu ...

  8. java将map拼接成“参数=值&参数=值”

    Java将Map拼接成"参数=值&参数=值" 把一个map的键值对拼接成"参数=值&参数=值"即"username=angusbao& ...

  9. 保留键的情况下取字典中最大的值(max\zip函数的联合使用)

    在我们平常想要获取字典中value最大或者最小的值的时候,常常使用如下函数: testDict = {"age1":18,"age2":20,"age ...

随机推荐

  1. 如何打开Tango的ADF文件?

    3ds max? opengl? ... Excel? vs? UltraEdit OpenGL Android API ADF文件数据结构:链接

  2. window.location 对象

    http://www.home.com:8080/windows/location/page.html?ver=1.0&id=timlq#love 1, window.location.hre ...

  3. VS2013的IDE开发使用便捷实用技巧----(补充)

    快捷键操作真的很高效.很酷······ 节省时间,提高开发效率 向人们展示可以惊讶到他们的功能,就像“我怎么就没发现”这种功能. 1. Peek View(本地查看程序源代码位置,便捷跳转) 可以在不 ...

  4. GameTOOL

    1.游戏的资源网站 http://www.gameres.com/yanfa_1.html

  5. 用jquery-table2excel,进行导出excel

    jquery-table2excel是一款可以将HTML表格的内容导出到微软Excel电子表格中的jQuery插件.该插件可以根据你的需要导出表格中的内容,不需要的行可以不导出. 它文件体积小,使用非 ...

  6. linq与数据库之添加

    这个是linq的添加显示 代码如下: //添加 private void button2_Click(object sender, EventArgs e) { string strstu = &qu ...

  7. .net core 2.1-----Sql Server数据库初体验

    刚开始接触asp.net core,在学习的过程中遇到了一些小问题,在这里记录一下! 在我们项目的开发过程中,肯定会和数据库打交道,所以我尝试了一下用asp.net core链接数据库,并读取表中的数 ...

  8. Syncthing源码解析 - 在Gogland中对Syncthing的各个模块进行调试?

    Syncthing的模块很多,各自负责不同的功能,如何能够对各个模块进行调试?Syncthing开发者早就想到这个问题了,允许开发者对任意模块进行单独调试,也允许同时对所有模块调试,调试方式是打印各个 ...

  9. Delphi XE7中开发安卓程序一些有用的帮助资源

    说明:要想看到下面资源,打开帮助后,在搜索里面输入URL最后一部分,如果最后带“.html”,则把它删除,随后搜索一下,就看到了. 例如:想看下面的FireMonkey类关系图,只在搜索里面输入&qu ...

  10. java的堆,栈,静态代码区 详解

    面试中,有家公司做数据库开发的,对内存要求比较高,考到了这个 一:在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register). 这是最快的存储区,因为它位于不同于其他存储区的地方— ...