Struts2 built a type converter, you can easily convert the string data we entered on the page into the JavaBean in the Boolean,float,integer,double,long and other data types, when the success can not be converted, but also to give error prompts, Very convenient
First Resume JavaBean:
Package HelloWorld;
public class User ... {
Private String username;
private Integer password;
Private string[] books;
Public string[] Getbooks () ... {
return to books;
}
public void Setbooks (string[] books) ... {
This.books = books;
}
Public String getusername () ... {
return username;
}
public void Setusername (String username) ... {
This.username = Username;
}
Public Integer GetPassword () ... {
return password;
}
public void SetPassword (Integer password) ... {
This.password = password;
}
}
Write action, you need to inherit actionsupport, there are two variables in the action, one is the user class, the other is the birth property
We define the birth property and the password attribute in the user class must be an integer type
Package HelloWorld;
Import Com.opensymphony.xwork2.ActionSupport;
public class Loginaction extends Actionsupport ... {
Private String tip;
private user user;
Private Integer birth;
Public Integer Getbirth () ... {
return birth;
}
public void Setbirth (Integer birth) ... {
This.birth = birth;
}
Public String Execute () throws Exception ... {
System.out.println (This.getuser (). GetUserName ());
System.out.println (This.getuser (). GetPassword ());
return SUCCESS;
}
Public User GetUser () ... {
return user;
}
public void SetUser (user user) ... {
This.user = user;
}
Public String gettip () ... {
return tip;
}
public void Settip (String tip)