<jsp:useBean> used to locate or sample a JavaBeans component. <jsp:useBean> will first attempt to locate a bean instance, and if the bean does not exist, then <jsp:useBean> will sample from a class or template.
In order to locate or sample a bean,<jsp:usebean>, the following steps are gathered, in the following order:
Attempts to locate a bean by a given name and range.
The reference variable for this Bean object is named after the name you specify.
If this bean is found, this reference will be stored in this variable. If you also specify a type, the bean is also set to the appropriate type.
If this bean is not found, it will be an example from the class you specified and store the reference in a new variable. If the name of this class represents a template, then the bean is java.beans.Beans.instantiate sample.
If <jsp:useBean> has an example (not positioned) of the bean, and there are elements in <jsp:useBean> and </jsp:useBean>, then the code will be executed.
The body of a <jsp:useBean> element usually contains a <jsp:setProperty> element that sets the value of the Bean's property. As mentioned in the fifth step above, the body of the,<jsp:usebean> is only executed when the <jsp:useBean> sample Bean is present, and if the bean already exists,<jsp:usebean> can locate it, Then the contents of the body will not work
Properties and Usage
Id= "Beaninstancename"
To confirm the bean's variables in the scope you defined, you can use this variable name in a later program to distinguish different beans
This variable name is case-sensitive and must conform to the scripting language you use, and in the Java programming Language, this rule is stated in the Java Language specification. If the bean is already created in another <jsp:useBean>, the value of this ID must be the same as the original ID value.
Scope= "page | Request | Session | Application "
The scope of the bean's existence and the valid range for the ID variable name. The default value is page, and the following is a detailed description:
Page-You can use the bean in the JSP file that contains the <jsp:useBean> element and all the static include files in this file until the page executes to send back a response to the client or go to another file.
Request-You use the bean in any JSP file that executes the same request until the page has finished executing to send back a response to the client or to another file. You can use the request object to access the bean, such as Request.getattribute (Beaninstancename)
Session-starting from the creation of the bean, You can use the bean in any JSP file that uses the same session. This bean exists throughout the session lifetime, and any JSP file that shares this session can use the same bean. Note <% @ in the JSP file where you created the bean Session=true must be specified in the page%> directive
Application-Starting from the creation of the bean, You can use the bean in any JSP file that uses the same application. This bean exists throughout the application lifecycle, and any JSP file that shares this application can use the same bean.
Class= "Package.class"
Use the New keyword and the class constructor to sample a bean from a class. This class cannot be abstract and must have a common, parameterless constructor. The name of this package differs in case.
Type= "Package.class"
If the bean already exists in the specified range, write the bean a new database type. If you do not use class or Beanname to specify Type,bean will not be examples. Package and class names are case-sensitive.
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.