JSP 教程 之 JSP JavaBean 2
JSP JavaBean
JavaBean 是特殊的 Java 类,使用 Java 语言书写,并且遵守 JavaBean API 规范。
JavaBean 程序示例
这是 StudentBean.java 文件:
package com.baidu;
public class StudentsBean implements java.io.Serializable
{
private String firstName = null;
private String lastName = null;
private int age = 0;
public StudentsBean() {
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public int getAge(){
return age;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public void setLastName(String lastName){
this.lastName = lastName;
}
public void setAge(int age) {
this.age = age;
}
}
编译 StudentBean.java 文件(最后一个实例会用到):
$ javac StudentsBean.java
编译后获得 StudentBean.class 文件,将其拷贝到 /WebContent/WEB-INF/classes/com/baidu