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"/>