Through the above study, we should have a basic understanding of JavaBean, for JavaServer pages in the call JavaBeans we also need to know some specific JSP content, let's take a look.
JavaBean related labels in JavaServer pages
Call JavaBean in JavaServer pages with three standard tags, that is <jsp:usebean>, <jsp:setproperty>, and <jsp:getProperty>.
<jsp:useBean> Label
<jsp:useBean> can define an instance of JavaBean with a certain range of existence and a unique ID so that JavaServer pages identify JavaBean by ID. You can also manipulate JavaBean by Id.method similar statements.
During execution,,<jsp:usebean> first tries to find a JavaBean instance that already exists with the same ID and scope value, and if not, a new instance is automatically created.
Its specific syntax is as follows
<jsp:usebean id= "Name"
Scope= "Page|request|session|application"
Typespec>
Body
</jsp:useBean>
The following table is the meaning of the related attributes in <jsp:useBean> tags
Attributes and Definitions
Id
The id attribute is the unique flag of the JavaBean object and represents an instance of a JavaBean object. It has a specific scope of existence (page|request|session|application). Identify JavaBean by ID in JavaServer pages.
Scope
The Scope property represents the lifetime of the JavaBean object, which can be one of page, request, session, and application.
Class
Represents the class name of the JavaBean object, paying special attention to the exact size of the case.
Beanname
The Beanname property represents the name of the bean and is typically initialized by the Tantiate () method of the Java.beans.Beans class.
Type
The Type property specifies the types of script variable definitions, and the default is that the script variable definition is consistent with the attributes in class, and we usually use the default value
<jsp:setProperty> Label
Another standard label is the <jsp:setProperty> tab, which is primarily used to set the Bean's property value. The syntax invoked in JavaServer pages is as follows:
<jsp:setproperty name= "Beanname" Last_syntax/>
Where the name attribute represents a JavaBean instance that already exists and has a certain living scope (scope). Last_syntax represents the following syntax: property= "*" |
Property= "PropertyName" |
Property= "PropertyName" param= "ParameterName" |
Property= "PropertyName" value= "PropertyValue"
The following are the basic attributes and implications of the <jsp:setProperty> label
Attributes and Definitions
Name
Name represents the JavaBean object instance defined through the <jsp:useBean> tag.
Property
This is an important attribute that represents the property name you want to set the value for. If you use property= "*", the program will repeatedly find all parameters of the current ServletRequest and match the property of the same name in JavaBean and assign value to this property by the set method of the property in JavaBean. If the Value property is empty, the property value in the JavaBean is not modified.
Param
The Param property represents the parameter name of the page request, and the $#@60;jsp:setproperty$#@62 label cannot use Param and value at the same time.
Value
The Value property represents the specific value of the attribute property that is assigned to the bean.
<jsp:getProperty> Label
The last tag is the <jsp:getProperty> tag. It can get the property values of the JavaBean instance, convert them to java.lang.String, and finally place them in an implied out object. An instance of JavaBean must be defined before <jsp:getProperty>.
The syntax of the <jsp:getProperty> label is as follows:
The following are the basic attributes and implications of the <jsp:getProperty> label
Attributes and Definitions
Name
The Name property represents an instance of the bean for which you want to obtain the property value, and the bean instance must be previously defined with the <jsp:useBean> label.
Property
The property attribute represents the name of the character that you want to get a value for.
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.