struts2中ognl在视图中访问对象的方法

struts2中ognl在视图中访问对象的方法

public class User implements Serializable{

 /**
  *
  */
 private static final long serialVersionUID = 1L;
 
 private String name;
 public User(){
  System.out.println("===============");
 }
 public User(String name){
  this.name = name;
 }

 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }
 
 @Override
 public String toString() {
  return "user="+this.name;
 }

}

public class UserAction extends ActionSupport{

 /**
  *
  */
 private static final long serialVersionUID = 1L;
 private String name;
 private User user;
 private Cat cat;
 
 @Override
 public String execute() throws Exception {
 // System.out.println(cat.getFriend().getName());
  return ActionSupport.SUCCESS;
  
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public User getUser() {
  return user;
 }
 public void setUser(User user) {
  this.user = user;
 }
 public Cat getCat() {
  return cat;
 }
 public void setCat(Cat cat) {
  this.cat = cat;
 }

}

  <s:property value="user.toString()"/>

你可能感兴趣的:(struts2中ognl在视图中访问对象的方法)