晕,容易啊BEAN里的操作就是一般的JDBC调用操作,然后页面里你图方便的话直接用SCRIPTLET搞个循环
就可以拉你再和他说,如果用TAGLIB来封装只要一个类HOHO

解决方案 »

  1.   

    //:~ Gslt_dbconnect.javaimport java.io.PrintStream;
    import java.sql.*;public class Gslt_dbconnect
    {    public Gslt_dbconnect()
        {
            sDBDriver = "org.gjt.mm.mysql.Driver";
            conn = null;
            rs = null;
            stmt = null;
            try
            {
                Class.forName(sDBDriver);
            }
            catch(ClassNotFoundException classnotfoundexception)
            {
                System.err.println("Class not found!" + classnotfoundexception.getMessage());
            }
        }    public ResultSet executeQuery(String s)
        {
            rs = null;
            try
            {
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gslt", "lhw", "lhw");
                stmt = conn.createStatement();
                rs = stmt.executeQuery(s);
            }
            catch(SQLException sqlexception)
            {
                System.err.println("aq.executeQuery:" + sqlexception.getMessage());
            }
            return rs;
        }    public int executeUpdate(String s)
        {
            int i = 0;
            try
            {
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/gslt", "lhw", "lhw");
                Statement statement = conn.createStatement();
                i = statement.executeUpdate(s);
            }
            catch(SQLException sqlexception)
            {
                System.err.println("aq.executeQuery:" + sqlexception.getMessage());
            }
            return i;
        }    public static void main(String args[])
        {
            String s = "select * from user_table";
            Gslt_dbconnect gslt_dbconnect = new Gslt_dbconnect();
            ResultSet resultset = null;
            resultset = gslt_dbconnect.executeQuery(s);
            System.out.println("begin:");
            try
            {
                String s3;
                for(; resultset.next(); System.out.println(s3))
                {
                    String s1 = resultset.getString("name");
                    System.out.println(s1);
                    String s2 = resultset.getString("address");
                    System.out.println(s2);
                    s3 = resultset.getString("email");
                }        }
            catch(SQLException _ex) { }
            System.out.println("end.");
        }    String sDBDriver;
        Connection conn;
        ResultSet rs;
        Statement stmt;
    //:~ insert1.jsp
    <%@ page contentType="text/html;charset=gb2312" %>
    <html>
    <head>
    <title>添加用户信息</title>
    </head>
    <body>
    <center><h2>添加用户信息</h2>
    <hr>
    <form action="insert_2.jsp" method="post">
    <p>姓名:<input type="text" id="name" name="name">
    <p>密码:<input type="password" id="passwordHash" name="passwordHash">
    <p>地址:<input type="text" id="address" name="address">
    <p>E-Mail:<input type="text" id="email" name="email">
    <p><input type="submit" id="confirm" name="confirm" value="确定">&nbsp;&nbsp;
       <input type="reset" id="reinput" name="reinput" value="重填">
    </p>
    </form></center>
    </body>
    </html>
    //:~ insert2.jsp
    <%@ page contentType="text/html;charset=gb2312" %><html>
    <head>
    <title></title>
    </head>
    <body>
    <center>
    <h2></h2>
    <hr>
    <%!String name;%>
    <%!String passwordHash;%>
    <%!String address;%>
    <%!String email;%><%
    name=request.getParameter("name");
        name = new String(name.getBytes("8859_1"), "gb2312");
    passwordHash=request.getParameter("passwordHash");
    passwordHash = new String(passwordHash.getBytes("8859_1"), "gb2312");
    address=request.getParameter("address");
    address = new String(address.getBytes("8859_1"), "gb2312");
    email=request.getParameter("email");
    email = new String(email.getBytes("8859_1"), "gb2312");
    %>
    <p>姓名:<%=name%>
    <p>密码:<%=passwordHash%>
    <p>地址:<%=address%>
    <p>E-Mail<%=email%>
    <form action="insert_3.jsp" method="post">
    <input type="hidden" id="name" name="name" value="<%=name%>">
    <input type="hidden" id="passwordHash" name="passwordHash" value="<%=passwordHash%>">
    <input type="hidden" id="address" name="address" value="<%=address%>">
    <input type="hidden" id="email" name="email" value="<%=email%>">
    <p><input type="submit" id="submit" name="confirm" value="确定">&nbsp;&nbsp;
       <input type="button" id="back" name="back" value="返回" onclick="javascript:history.go(-1)">
    </p>
    </form>
    </center>
    </body>
    <html>//:~ insert3.jsp<%@ page language="java" import="java.sql.*" %>
    <%@ page contentType="text/html;charset=gb2312"%><jsp:useBean id="insert" scope="page" class="com.nes.gslt.db.Gslt_dbconnect"/><html>
    <head>
    <title>添加用户信息</title>
    </head>
    <body><%!String name;%>
    <%!String passwordHash;%>
    <%!String address;%>
    <%!String email;%>
    <%
    name=request.getParameter("name");
    String name1 = name;
    name1 = new String(name1.getBytes("8859_1"), "gb2312");

    passwordHash=request.getParameter("passwordHash");
    address=request.getParameter("address");
    email=request.getParameter("email");

    %>
    <%
    String sql_1="insert into user_table(name,passwordHash,address,email)";
    sql_1= sql_1 + "values('" + name + "','" + passwordHash + "','" + address + "','" + email + "')";
    System.out.println(sql_1);
    insert.executeUpdate(sql_1);

    %><center>
    <h2>添加用户信息</h2>
    <hr><br>
    <font color="blue"><%=name1%></font>的用户信息已经添加到数据库中!
    <form action="user_manage.html" method="post">
    <input type="submit" id = "back" name="back" value="返回">
    </form>
    </center>
    </body>
    </html>
      

  2.   

    更好的模式是将bean存储层和数据库访问层分开。写两个类。