A bean is simply a class that adheres to the following rules.
For example, lets say you've created a dynamic web application that contains a package named com.sample.main.
And then you've created a class called People in the package.
Add the following to MyBean.java. This bean will display the text "John Doe".
package com.sample.main;
// implement java.io.Serializable
public class MyBean implements java.io.Serializable {
// private variables
private static final long serialVersionUID = -3774654564564563L;
private String name;
// constructor
public MyBean() {
name = "Jane Doe";
}
public MyBean(String name) {
this.name = name;
}
// getter
public String getName() {
return name;
}
// setter
public void setName(String name) {
this.name = name;
}
}
The bean can be imported into a JSP page.