Tip: What is JavaBean

Source: Internet
Author: User

JavaBean is a Java class that follows a specific notation, and it usually has the following characteristics:

    • This Java class must have an argument-free constructor
    • property must be privatized.
    • The properties of privatization must be exposed to other programs through methods of public type, and the naming of methods must follow certain naming conventions.
    1. While Sun is defining the JavaBean specification, it allows Java developers to design JavaBean to be as powerful as swing components, but in the actual development of Java EE, the most basic features of the above JavaBean are usually used only.
    2. JavaBean is typically used to encapsulate data in a Java EE development, and for JavaBean components that follow the above notation, other programs can instantiate JavaBean objects through reflection technology, and learn the properties of JavaBean by reflecting the methods that obey the naming conventions. It then calls its properties to save the data.
    • JSP technology provides three action elements about the JavaBean component, the JSP tags, which are:

<jsp:useBean> Tags: used to find or instantiate a JavaBean component in a JSP page.
<jsp:setProperty> Tags: used to set the properties of a JavaBean component in a JSP page.
<jsp:getProperty> Tags: used to get the properties of a JavaBean component in a JSP page.

The <jsp:useBean> tag is used to find the JavaBean object of the specified name within the specified domain scope:
Returns a reference to the JavaBean object directly if it exists.
Instantiates a new JavaBean object if it does not exist and stores it in the specified domain scope with the specified name.

    • Common syntax:

<jsp:usebean id= "Beanname" class= "Package.class"
Scope= "Page|request|session|application"/>

    • The ID property is used to specify the reference name of the JavaBean instance object and its name stored in the domain scope.
    • The class attribute is used to specify the full class name of the JavaBean (that is, it must have a package name).
    • The scope property specifies the domain scope stored by the JavaBean instance object, which can only be one of four values, such as page, request, session, and application, and its default value is page.

tip:<jsp:usebean> Principle of execution

class= "Java.util.Date"/>null; synchronized (_jspx_page_context) {    = (java.util.Date) _jspx_page_context.getattribute ("currentdate"  , pagecontext.page_scope);     if NULL ) {        new  java.util.Date ();        _jspx_page_context.setattribute ("currentdate", currentdate, pagecontext.page_scope);    }}

Tip: <jsp:setProperty> Tags

The <jsp:setProperty> tab is used to set and access the properties of the JavaBean object. Syntax format:<jsp:setproperty name= "Beanname" {     property = "PropertyName" value= "{string | <%= Expression%>} "|     property = "PropertyName" [param= "ParameterName"] |      property= "*"  //With all request parameters for bean assignment}the/>Name property is used to specify the name of the JavaBean object. The property attribute is used to specify the attribute name of the JavaBean instance object. The Value property is used to specify values for a property of the JavaBean object, which can be either a string or an expression. As a string, the value is automatically converted to the corresponding type of the JavaBean property.
If the value of value is an expression, the expression must evaluate to the same type as the JavaBean property you want to set.

Tip: What is JavaBean

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.