1. A standard JavaBean should have the following characteristics:
(1) must be a public class, that is, the class access permission for JavaBean must be publicly.
(2) must have a parameterless construction method. If you define a custom, parameterized construction method in JavaBean, you must add a parameterless construction method, otherwise you will not be able to set the property, or you can use the compiler to automatically add an parameterless construction method if you do not define a custom, parametric construction method.
(3) JavaBean generally set properties to private, using the GetXXX () method and the Setxxx () method to obtain and set properties.
The syntax format is as follows:
<jsp:usebean id= "Object name" scope= "Storage Scope" class= "package name + class name" ></jsp:useBean>
Note: (1) The id attribute represents the name of the object after the JavaBean instantiation.
(2) The scope attribute is used to specify the range of the JavaBean. There are four range values: page, request, session, application
(3) The class attribute is used to specify the name of the JavaBean, to write the full-package name and the class name.
2. Setting the JavaBean Property
JSP provides a <jsp:setProperty> action instruction to set the JavaBean property, which has the following four syntax formats:
(1) <jsp:setproperty name= "instantiating object name" property= "*"/>
(2) <jsp:serproperty name= "Instantiate object Name" property= "property name"/>
(3) <jsp:setproperty name= "Instantiate object Name" property= "property name" param= "Accept parameter name"/>
(4) <jsp:setproperty name= "instantiating the object name" property= "property name" Value= "property value"/>
Note: Where the Name property is set to instantiate the object name, and the id attribute in <jsp:useBean> is to be consistent.
3. Get JavaBean Properties
The syntax format is as follows:
<jsp:getproperty name= "Instantiating the object name" property= "property name"/>
4. Removal of JavaBean
JavaBean will determine its life cycle based on its set range, and JavaBean will be removed automatically when the lifecycle ends. It can also be manually removed, saving memory.
JavaBean removal is different for different ranges of JavaBean, calling PageContext, request, Session, application RemoveAttribute (String name), respectively method to remove the JavaBean. Where the Name property is set to instantiate the object name and must be consistent with the id attribute in <jsp:useBean>.
(v) JSP and JavaBean