标签:strong ica cal type editor different submit inpu instant
参看维基百科,归纳出以下几条:
JavaBeans是指符合某些标准的类,
Bean这个名称用于涵盖这个标准,
其目的在于创建可重用的Java组件。
由于Bean是很“死板”的东西,因此它可以持久存储,并可以借助辅助软件快速实现。
Bean有它专属的一套API。
In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect Java Beans.
The required conventions are as follows:
实例,1无参构造器 2getter, setter 3实现序列化
package player; public class PersonBean implements java.io.Serializable { /** * Property <code>name</code> (note capitalization) readable/writable. */ private String name = null; private boolean deceased = false; private List list; public List getList() { return list; } public void setList(List list) { this.list= list; } /** No-arg constructor (takes no arguments). */ public PersonBean() { } /** * Getter for property <code>name</code> */ public String getName() { return name; } /** * Setter for property <code>name</code>. * @param value */ public void setName(final String value) { name = value; } /** * Getter for property "deceased" * Different syntax for a boolean field (is vs. get) */ public boolean isDeceased() { return deceased; } /** * Setter for property <code>deceased</code>. * @param value */ public void setDeceased(final boolean value) { deceased = value; } }
在JSP页面中使用PersonBean:
<% // Use of PersonBean in a JSP. %> <jsp:useBean id="person" class="player.PersonBean" scope="page"/> <jsp:setProperty name="person" property="*"/> <html> <body> Name: <jsp:getProperty name="person" property="name"/><br/> Deceased? <jsp:getProperty name="person" property="deceased"/><br/> <br/> <form name="beanTest" method="POST" action="testPersonBean.jsp"> Enter a name: <input type="text" name="name" size="50"><br/> Choose an option: <select name="deceased"> <option value="false">Alive</option> <option value="true">Dead</option> </select> <input type="submit" value="Test the Bean"> </form> </body> </html>
标签:strong ica cal type editor different submit inpu instant
原文地址:http://www.cnblogs.com/xkxf/p/7004027.html