JavaBean usage Analysis of JSP learning _jsp programming

Source: Internet
Author: User

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.

Related Article

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.