The JavaBean of Web beginners

Source: Internet
Author: User

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

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.