The concept of JAVA Web:javabean

Source: Internet
Author: User

JavaBean is a reusable, cross-platform software component. JavaBean can be divided into two types: one is a user interface

Another is that there is no user interface, mainly responsible for processing transactions (such as data operations, manipulating the database) JavaBean. The JSP typically accesses the latter type of JavaBean.

Advantages of using JSP and JavaBean:

1. Make HTML and Java programs separate, so that the maintenance of code, if all the program code is written in the JSP Web page, will make the code cumbersome, difficult to maintain

2. Can reduce the development of JSP Web page personnel on the Java programming ability requirements

3.JSP focuses on generating dynamic web pages, and transactions are done by JavaBean, which can take advantage of the reusability of JavaBean components and improve the efficiency of the development site.

MVC design Pattern (model View Controller)

A standard JavaBean has the following properties

--javabean is a common (public) tired

--javabean has a construction method with no parameters

--javabean properties are set through the Setxxx method, and properties are obtained through the GetXXX method

7. A typical JavaBean class

1  Public classcounterbean{2       Private intcount;3        PublicCounterbean () {}//an empty constructor4        Public intGetCount () {5                 returncount;6           }7 8 9         Public voidSetCount (intcount) {Ten                  This. count=count;  One           }   A      -}

Syntax for JSP access JavaBean

1. Import the JavaBean class

2. Declaring JavaBean objects

3. Accessing JavaBean objects

9. Enter the JavaBean class via the <%@ page import> directive such as:

Import= "Mypack. Counterbean "%>

Use <jsp:useBean>

1 <jsp:usebean id= "Mybean"2       class= "Mypack. Counterbean "scope=" Session "/>34 <jsp:usebean id=" mybean_1 "5       class= "Mypack. Counterbean "scope=" Session "/>

Properties and Usage:

Id= "Xxxxbeanname"

Confirm the bean's variable in the defined scope so that it can differentiate the bean from the other side. If the bean is already created in another Userbean tag, the value of the bean,id that has already been created must be consistent with the original ID, otherwise it would mean that two different objects of the same class were created.

        <Jsp:usebeanID= "Person"class= "Com.shengsiyuan.bean.Person"></Jsp:usebean>                        <Jsp:getproperty Property= "Name"name= "Person"/>        <Jsp:getproperty Property= "Age"name= "Person"/>        <Jsp:getproperty Property= "Address"name= "Person"/>

The above is actually written in the servlet source code.

        <%=new%>        <%=% >

will be translated into this way, the Usebean tag will generate a person object named man.

The Scope property determines the extent to which the JavaBean object exists, and the scope optional values include:

-page

-request

-session

-application

Concepts of JAVA Web:javabean

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.