Introduction to the use of STRUTS2 built-in type converter data

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.