JSP and Java Bean

Source: Internet
Author: User

This document briefly introduces Java Bean. It mainly includes:

1. Java Bean Lifecycle

2. Common JSP labels of Java Bean

3. Simple Java Bean demo

1. Java Bean Lifecycle

    • Page, for a specific web page, each web page browsing is a new requirement.
    • Request is a service for the same requet. Therefore, each web page browsing is a new requirement.
    • Session. If you do not care about each browser, the total number is counted.
    • Application.

2. Common Java Bean labels and demos

Helloworldbean. Java

Package beans; <br/>/** <br/> * @ author jefferyxu <br/> */<br/> public class helloworldbean {<br/> private string STR = "Hello world. "; <br/>/** <br/> * @ return the STR <br/> */<br/> Public String getstr () {<br/> return STR; <br/>}< br/>/** <br/> * @ Param STR the STR to set <br/> */<br/> Public void setstr (string Str) {<br/> This. STR = STR; <br/>}< br/>

JSP page:

<Body> <br/> <! -- Declare to use this bean --> <br/> <JSP: usebean id = "hello" class = "beans. helloworldbean "> <br/> </jsp: usebean> </P> <p> <! -- Set and modify bean Attributes --> <br/> <JSP: setproperty name = "hello" property = "str" value = "set Hello World"/> </P> <p> <! -- Get the corresponding Property --> <br/> <JSP: getproperty name = "hello" property = "str"/> <br/> </body>

Note that if <JSP: setproperty name = "hello" property = "str" value = "set Hello World"> </jsp: setproperty> is written in this way, possible error:

Org. Apache. Jasper. jasperexception:/index. jsp (26,4) According to TLD, tag JSP: setproperty must be empty, but is not <br/>

Change it to the following:

<! -- Set and modify bean Attributes --> <br/> <JSP: setproperty name = "hello" property = "str" value = "set Hello World"/>

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.