JavaBean
class 1.javaBean: Special java classes for encapsulation and reuse purposes. Often JavaBean is used in conjunction with Jsp to form JavaBean technology.
(1) Specifications for JavaBean:
JavaBean is a public class .
has a non-parametric constructor (that is, the default constructor method)
Provides the setxxx () method and the getXxx () method
(2) Code example :
PackageCom.chapter07.javabean; Public classPerson {PrivateString name; Private intAge ; PrivateString address; /*Public Person () {name= "HHHH"; age=12; Address= "121232"; }*/ PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public intGetage () {returnAge ; } Public voidSetage (intAge ) { This. Age =Age ; } PublicString getaddress () {returnaddress; } Public voidsetaddress (String address) { This. Address =address; }}
2. JSP action elements :
(1) <jsp:usebean>: established scope to find a name-setting JavaBean object that exists as a direct return
Returns a reference to the JavaBean object that does not exist and instantiates a new JavaBean object.
Example:
(2) <jsp:setproperty>: Assigning values to a JavaBean property, and <jsp:useBean> Action with. Can be used between the <jsp:useBean> element start tag and the terminating tag, where its properties are initialized when the JavaBean object is instantiated.
Example:
(3) <jsp:getProperty> used to get a property value from a JavaBean , it is converted to a value of type String.
Example :
The JavaBean of Web beginners