According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is based on the java language, so do not rely on JavaBean platform have the following characteristics:
1. Can achieve code reuse
2. Easy to prepare, easy to maintain, easy to use
3. Can be installed in any Java runtime environment using the platform without the need to recompile.
Prepared JavaBean is the preparation of a java class, so you can type and write as long as the preparation of a bean, the class created an object called a bean. Use this bean in order to allow the application to build tools (such as JSP engine) that this bean's properties and methods, simply type the name of the method comply with the following rules:
1. If the class member variable name is xxx, then in order to change or access to the members of the variable's value, that is, to change or access to property, in the class can use two methods:
getXxx (), used to obtain property xxx.
setXxx (), used to modify property xxx..
2. For boolean types of member variables, that is, Boolean logic types of property, permit the use of "is" in lieu of the above "get" and "set".
3. Ways to visit the class must be public property of the.
4. If the class has constructor, then the constructor is public and is free of parameters.

-------------------------------------------------- --------
In the servlet use Bean and Bean are usually used in similar procedures
The first letter of property names must be lowercase, for example: private productId
Generally has getters and setters
But Bean should not have the GUI performance
Generally are used to achieve a certain business logic or to obtain a specific result
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DB {

	public static Connection getConnection(){
		Connection conn= null;
		try{
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/ssh?user=root&password=123456");
		}catch(SQLException e){
			e.printStackTrace();
		}catch(ClassNotFoundException e){
			e.printStackTrace();
		}
		return conn;
	}
	public static Statement getrStatement(Connection conn){
		Statement stmt = null;
		try {
			stmt = conn.createStatement();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return stmt;
	}
	public static ResultSet getResultset(Statement stmt,String sql){
		ResultSet rs = null;
		try {
			rs = stmt.executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rs;
	}
	public static void close(Connection conn){
		if(conn != null){
			try {
				if(!conn.isClosed()){
					conn.close();
					conn = null;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void close(Statement stmt){
		if(stmt != null){
			try {	
					stmt.close();
					stmt = null;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void close(ResultSet rs){
		if(rs != null){
			try {
					rs.close();
					rs = null;
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ShowRsUseBeanServlet extends HttpServlet{

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		response.setContentType("text/html");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.println("<table border='1'>");
		out.println("<tr><td>content</td></tr>");
		
		Connection conn = DB.getConnection();
		Statement stmt = DB.getrStatement(conn);
		String sql = "select * from t_user";
		ResultSet rs = DB.getResultset(stmt, sql);
		
		try {
			while(rs.next()){
				out.println("<tr>");
				out.println("<td>"+rs.getString("name")+"</td>");
				out.println("</tr>");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		out.println("</table>");
		
		DB.close(rs);
		DB.close(stmt);
		DB.close(conn);
	}
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

	<servlet>
		<servlet-name>ShowRsUseBeanServlet</servlet-name>
		<servlet-class>ShowRsUseBeanServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>ShowRsUseBeanServlet</servlet-name>
		<url-pattern>/ShowRsUseBeanServlet</url-pattern>
	</servlet-mapping>

</web-app>