用到的类有:

相应代码:

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>

效果:

最新文章

  1. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
  2. Linux第三周——跟踪分析内核的启动过程
  3. python实现支持并发、断点续传的Ftp程序
  4. 数据库优化实践【TSQL篇】
  5. Qt 二级菜单栏 中文无法输入问题
  6. flexible.js
  7. Cocos2d-JS坐标系
  8. HttpClient post中文乱码解决
  9. 【转】理解 Android Build 系统----不错
  10. 扩展jquery.validate自定义验证,自定义提示,本地化
  11. 首次在C#程序中用log4net
  12. Rewrite JSON project with Fetch
  13. COOKIE和SESSION之间的区别以及用法
  14. python----re正则模块详解
  15. Delaunay triangulation
  16. Pytorch安装(基于anaconda虚拟环境)
  17. maven 引入外部jar包的几种方式
  18. 万恶之源 - Python初识函数
  19. php不用递归完成无限分类,从表设计入手完整演示过程
  20. C#基础学习之委托的理解和应用

热门文章

  1. FTP服务器的搭建与安全配置
  2. bootstrap-table简单使用
  3. Java容器中的元素输出
  4. kvm虚拟化存储池配置
  5. “全栈2019”Java异常第七章:try-catch-finally组合方式
  6. python中多线程,多进程,多协程概念及编程上的应用
  7. acedSSGet 翻译
  8. hadoop-1.2.1-1.x86_64.rpm、jdk-7u45-linux-x64.tar.gz安装(64位)
  9. 架构师养成记--25.linux用户管理
  10. 第一站:CLion安装教程与环境配置