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

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. ImageData

    http://www.html5china.com/HTML5features/canvas/20120501_3591.html 1.上下文对象 Context 有三个方法用来创建.读取和设置 Im ...

  2. Easyui Datagrid扩展fixRownumber方法

    首先,从datagrid生成的代码,我们可以发现,在rowNumber上都有特定的class标记,datagrid-cell-rownumber,datagrid-header-rownumber. ...

  3. 学习spring1--跟我一起学Spring 3(2)–开发环境配置

    http://www.importnew.com/13185.html#spring     首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 我要投稿 更多频道 » - 导航条 - 首页 所 ...

  4. OpenCV中Kinect的使用(2)

    接OpenCV中Kinect的使用(1),主要讲述OpenCV中关于Kinect接口(类 VideoCapture )的一些使用介绍. 类 VideoCapture 支持Kinect传感器.使用 Vi ...

  5. linux shell习题训练

    shell习题训练 求2个数之和 计算1-100的和 将一目录下所有的文件的扩展名改为bak 编译当前目录下的所有.c文件: 打印root可以使用可执行文件数,处理结果: root's bins: 2 ...

  6. boot2docker里报"no space left on device" error的解决方法

    docker中pull远程image时:报 no space left on device virtualbox中调大虚拟内存即可.. 之前调的硬盘大小...

  7. 使用sqoop1.4.4从oracle导入数据到hive中错误记录及解决方案

    在使用命令导数据过程中,出现如下错误 sqoop import --hive-import --connect jdbc:oracle:thin:@192.168.29.16:1521/testdb ...

  8. OpenCV学习笔记十五:opencv_features2d模块

    一,简介: 该库用于2D特征检测,描述与匹配.

  9. day2 python基础 while 循环补充

    一.上节内容回顾 二.pycharm安装. 安装好以后激活方法:直接打开pycharm,选License server激活,输入:http://idea.imsxm.com 三.补充知识:如果字符串本 ...

  10. 谈抽象1——无脑copy等于自杀

    近期被外派帮助国内某公司做政府某部门OA系统.听说他们那有个成熟的java框架,使用了非常长时间,抱着学习的态度,我进入这个公司.当我熟悉了一周后,留下了非常多疑问,而这些疑问,也诱发了这次关于&qu ...