参看维基百科,归纳出以下几条:

JavaBeans是指符合某些标准的类,

Bean这个名称用于涵盖这个标准,

其目的在于创建可重用的Java组件。
由于Bean是很“死板”的东西,因此它可以持久存储,并可以借助辅助软件快速实现。
Bean有它专属的一套API。

JavaBean conventions[edit]

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:

  • The class must have a public default constructor (with no arguments). This allows easy instantiation within editing and activation frameworks.
  • The class properties must be accessible using getsetis (can be used for boolean properties instead of get), and other methods (so-called accessor methods and mutator methods) according to a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. Setters can have one or more than one argument.
  • The class should be serializable. (This allows applications and frameworks to reliably save, store, and restore the bean's state in a manner independent of the VM and of the platform.)

实例,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>

什么是JavaBeans?的更多相关文章

  1. 找规律 ZOJ3498 Javabeans

    Javabeans are delicious. Javaman likes to eat javabeans very much. Javaman has n boxes of javabeans. ...

  2. JavaBeans、EJB和POJO详解

    转自:http://developer.51cto.com/art/200906/130814.htm J2EE学习者越来越多,J2EE本身技术不断在发展,涌现出各种概念,本文章试图从一种轻易理解的角 ...

  3. Java遇见HTML——JSP篇之JavaBeans

    一.JavaBean简介及设计原则 设计原则:公有类.无参的公有构造方法.属性私有.有getter and setter方法 实例: 二.Jsp动作元素 JSP动作标签分为五大类: 三.在JSP页面中 ...

  4. javabeans的运用

    javabeans的运用 对javabean的使用我开始严重的郁闷,跟着书上说的做,但是总是不成功.后来别人说我是基础不牢靠.我觉得应该从servlet学起然后再加进入JSP学是非常快的,对于JAVA ...

  5. [基础规范]JavaBeans规范

    本文来自维基百科:http://en.wikipedia.org/wiki/JavaBeans#JavaBean_conventions JavaBeans是Java语言中能够反复使用的软件组件,它们 ...

  6. Java Web 之javabeans

    Java遇见HTML——JSP篇之JavaBeans: http://www.cnblogs.com/Qian123/p/5277425.html

  7. Java各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分

    PO:持久对象 (persistent object),po(persistent object)就是在Object/Relation Mapping框架中的Entity,po的每个属性基本上都对应数 ...

  8. Java开发各层对象专用名词含义 PO,VO,DAO,BO,DTO,POJO, BYO,Entity,JavaBean,JavaBeans

    Java的几种名词(PO,VO,DAO,BO,POJO)解释 PO:persistant object 持久对象.可以看成是与数据库中的表相映射的java对象.最简单的PO就是对应数据库中某个表中的一 ...

  9. Java学习之——JavaBeans

    1.什么是JavaBeans? JavaBeans是Java语言中可以重复使用的软件组件,它们是一种特殊的Java类,将很多的对象封装到了一个对象(bean)中.特点是 可序列化, 提供无参构造器, ...

  10. JavaBeans 官方文档学习

    提示,重点:JavaBeans的Property和 Events:PropertyEditor极其注册和查找机制. 从目前来看,JavaBeans 更像是源自GUI的需求. 使用NetBeans新建一 ...

随机推荐

  1. FFMPEG中关于ts流的时长估计的实现

    ts流中的时间估计 我们知道ts流中是没有时间信息的,我门来看看ffmpeg是怎么估计其duration的 方法1.通过pts来估计 static void estimate_timings_from ...

  2. 第一百七十八节,jQuery-UI,知问前端--对话框 UI

    jQuery-UI,知问前端--对话框 UI 学习要点: 1.开启多个 dialog 2.修改 dialog 样式 3.dialog()方法的属性 4.dialog()方法的事件 5.dialog 中 ...

  3. JSP接口浅析

    一.tree型关系 JSP页面继承了org.apache.jasper.runtime.HttpJspBase抽象类并实现了org.apache.jasper.runtime.JspSourceDep ...

  4. python 爬虫5 Beautiful Soup的用法

    1.创建 Beautiful Soup 对象 from bs4 import BeautifulSoup html = """ <html><head& ...

  5. genymotion启动报错

    启动genymotion时提示 网络配置有问题,经检查是网卡virtualBox配置的问题,把ip设为自动获取即可 重新启动就可以了

  6. asp.net中TextBox只能输入数字的最简洁的两种方法

    如下TextBox <asp:textboxonkeypress="isnum()"id="TextBox1"runat="server&quo ...

  7. 设计模式之备忘录模式(Memento)

    备忘录模式(Memento) 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象之外保存这个状态.这样以后就可将该对象恢复到原先保存的状态. Originator(发起人):负责创建一个备忘录 ...

  8. python3 - 闭包

    # 定义一个函数def test(number): # 在函数内部再定义一个函数,并且这个函数用到外边函数的变量, # 那么将这个函数以及用到的一些变量称之为 闭包. def text_in(numb ...

  9. python redis操作

    import redis r = redis.Redis( host='1xx.x24.3xx.x0', #ip, password='xnxnxn&*',#密码 port=6379, #端口 ...

  10. chm文件无法阅读

    当我们费劲千辛万苦从网上下载好chm文件资料后,打开后发现竟然是这个样子的: 其中主要原因是CHM文件被阻止显示了,CHM文件在NTFS格式的硬盘里的时候就会被阻止显示.我们返回我的电脑,点中我们存放 ...