pure OGNL example without struts2,for the benefit of your completely understanding it.
public class User {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class Customer {
private User user;
private String name;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
import ognl.Ognl;
import ognl.OgnlException;
public class testOGNL {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Customer customer = new Customer();
User user = new User();
customer.setUser(user);
Object tree = Ognl.parseExpression("user.name");
Ognl.setValue(tree, customer, "刘利新");
System.out.println(Ognl.getValue(tree, customer));
System.out.println(user.getName());
} catch (OgnlException e) {
e.printStackTrace();
}
}
}
含库源代码:http://pan.baidu.com/share/link?shareid=3022756736&uk=3878681452