This article illustrates the JavaBean usage of JSP learning. Share to everyone for your reference. Specifically as follows:
JavaBean is a Java class that conforms to certain naming methods and design specifications
JavaBean can be used to perform complex computational tasks, encapsulate transaction logic, database operations, etc.
JavaBean are divided into visual JavaBean, such as buttons, text boxes, list boxes, and so on. and Non-visual JavaBean, such as operations, database connections, etc.
Use JavaBean:
Copy Code code as follows:
<jsp:usebean id= "name" scope= "Page|request|session|application" typespec= "TypeName"/>
TypeSpec four kinds of values:
class= "ClassName" class indicates class path and class name
The class= "classname" type= "TypeName" type represents the types of classes, either this class, the parent class, or the interface
Beanname= "Beanname" Type= "TypeName", Beanname represents JavaBean name, initialized by the Java.beans.Beans.instantiate () method, in the form of A.B.C
Type= "TypeName"
<jsp:setProperty> to set property values for JavaBean:
<jsp:setproperty name= "Beanname" property= "*" > <jsp:setproperty name= "beanname"
PropertyName ">
<jsp:setproperty name=" Beanname "property=" PropertyName "param=" ParamName ">
< Jsp:setproperty name= "Beanname" property= "PropertyName" value= "Beanvalue" >
Beanname represents JavaBean instance name, introduced with <jsp:usebean>
PropertyName represents the property name of the JavaBean
PARAMNAME Specifies the name of the parameter in the Request object
Beanvalue is used to set the JavaBean property value
<jsp:getProperty> to get property values for JavaBean:
<jsp:getproperty name= "Beanname" property= "PropertyName" >
Equivalent to the GETXX function in JavaBean.
<jsp:setproperty name= "Splbean" property= "id" value= "${param.id}"/>
about the declaration cycle for JavaBean:
Page Range-> life cycle can only be in one page, can only access the JavaBean in one page, refresh the page will remove the original JavaBean instance, resulting in a new JavaBean instance.
The request scope-> has a lot to do with the request object, in addition to the entire page, including action elements <jsp:include> and <jsp:forward> included pages, That is, the original page and the included pages can access the original generated JavaBean instance
Session scope: Lifecycle in a connection, you can access the JavaBean in a connection (when a user accesses a Web page using a browser, a connection is made, and a Session object representing the connection is created).
Application scope: The longest life cycle, as long as the Web server does not restart, JavaBean will always run in the server, so any page can use the JavaBean instance.
I hope this article will help you with the JSP program design.