本人最近需要用JSP做一个网站,但是本人之前没学过JSP,我想问一下我在一个页面布置了一个类似于表格的东西,需要别人填写信息,然后将这些信息传送到MySQL数据库中,我只编出了界面,但是不知道接下来怎么做,请各位高手指点一下
<tr>
 <th width=160>毕业设计(论文)题目</th>
 <th width=300><input type=text value=""></th>
 </tr>
 <tr>
 <th width=160>院 (部)</th>
 <th width=300><input type=text value=""></th>
 <th width=160>指导老师</th>
 <th width=300><input type=text value=""></th>
 </tr>
 <tr>
  <th width=160>专业</th>
 <th width=300><input type=text value=""></th>
 <th width=160>班级</th>
 <th width=300><input type=text value=""></th>
 </tr>
  <tr>
  <th width=160>学生学号</th>
 <th width=300><input type=text value=""></th>
 <th width=160>学生姓名</th>
 <th width=300><input type=text value=""></th>
 </tr>
   <tr>
  <th width=160>课题来源</th>
 <th width=300><input type=text value=""></th>
 <th width=160>课题类别</th>
 <th width=300><input type=text value=""></th>
 </tr>
   <tr>
  <th width=160>课题来源</th>
 <th width=300><input type=text value=""></th>
 <th width=160>课题类别</th>
 <th width=300><input type=text value=""></th>
 </tr>
个人认为要在input type=text value=""里面填写一些东西,但不知道怎么填写,另外<form>里面需要改么,求指点

解决方案 »

  1.   

    请教高手java怎么和数据库链接
      

  2.   

    我最近 也在看jsp,可以通过jdbc链接数据库。
      

  3.   

    google 一下jdbc吧 很简单的
      

  4.   

    最简单的方式:
    1.获取数据库连接
       public static  Connection  getConnection() throws SQLException{

    String driver="com.mysql.jdbc.Driver";
    String url="jdbc:mysql://localhost:3306/test";
    String user="root";
    String pwd="admin";
    Connection conn=null;
    try
    {
    Class.forName(driver);
    conn = DriverManager.getConnection(url, user, pwd);


    }
    catch (Exception e)
    {

    e.printStackTrace();
    }finally{

    if(conn != null){

    conn.close();
    }

    }
    return conn;

    }2.插入记录到数据库
     
      public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
               

         String usernameString = request.getParameter("username");
          Connection con = getConnection();
                 String sql = "insert into adduser (op_name,op_time) values (?,sysdate())";
    PreparedStatement pstmt = con.prepareStatement(sql);
           pstmt.setString(1, "dunsan");
    boolean b = pstmt.execute();
           
    }
      

  5.   

    在网上找一个JSP的小项目看看,照着做。
      

  6.   

    感谢各位大神们的指点,我还想知道一个文本输入框里面输入的信息要怎么弄进数据库
    input type="text" value=""
    后面应该还有个什么东西,好像是导入数据库所用到的方法,那个应该怎么写
      

  7.   

    好多手写的,大概思路是那样的吧
    找的一个JAVABEAN,
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;public class DB {
    public static Connection getConn() {
    Connection conn = null;
    try {
    Class.forName("com.mysql.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs", "root" , "123456");
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return conn;
    }

    public static Statement createStmt(Connection conn) {
    Statement stmt = null;
    try {
    stmt = conn.createStatement();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return stmt;
    }

    public static ResultSet executeQuery(Statement stmt, String sql) {
    ResultSet rs = null;
    try {
    rs = stmt.executeQuery(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return rs;
    }

    /*public static ResultSet executeQuery(Connection conn, String sql) {
    Statement stmt = null;
    ResultSet rs = null;
    try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    }

    // finally {
    // close(stmt);
    // }


    return rs;
    }*/

    public static int executeUpdate(Connection conn, String sql) {
    int ret = 0;
    Statement stmt = null;
    try {
    stmt = conn.createStatement();
    ret = stmt.executeUpdate(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    close(stmt);
    }
    return ret;
    }

    public static PreparedStatement prepareStmt(Connection conn, String sql) {
    PreparedStatement pstmt = null;
    try {
    pstmt = conn.prepareStatement(sql);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return pstmt;
    }

    public static PreparedStatement prepareStmt(Connection conn, String sql, int autoGeneratedKeys) {
    PreparedStatement pstmt = null;
    try {
    pstmt = conn.prepareStatement(sql, autoGeneratedKeys);
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return pstmt;
    }

    public static void close(Connection conn) {
    if(conn != null) {
    try {
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    conn = null;
    }
    }

    public static void close(Statement stmt) {
    if(stmt != null) {
    try {
    stmt.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    stmt = null;
    }
    }

    public static void close(ResultSet rs) {
    if(rs != null) {
    try {
    rs.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    rs = null;
    }
    }
    }add.jsp
    <form>
    <table>
    <tr>
    <td>
    <input type="text" name="x1" id="x1">
    ......
    </td>
    </tr>
    </table>
    </form>
    Into_data.jsp
    <%@ page language="java" import="java.util.*, java.sql.*, yuhaibin.*" pageEncoding="GB18030"%>
    <% String x1=request.getParameter("x1");
    .......
       Connection conn=DB.getConn;
       conn.setAutoCommit(false);
    String sql="insert into datatable values(x1,...)";
    Statement stmt=DB.createStmt(conn);
    stmt.executeUpdate(sql);
    conn.commit();
    conn.setAutoCommit(true);
    DB.close(stmt);
    DB.close(conn);
    ...
    %>
       
      

  8.   

    <tr>
         <td><div align="right">用户名:</div></td>
         <td><input name="cname" type="text" id="cname"></td>
         </tr>
      

  9.   


    LZ可以看看LS 的这个正解……多看看JSP的内置对象和标签库,基本上就可以掌握JSP了……
      

  10.   

    楼主要在表格外面再套一个
    <form action="" method="post">
    <table></table>
    <input type="submit" value="提交"/>
    </form>
    action=""中写的是你需要提交给的连接地址
    例如:action="项目名字/包名/xxx";
    上面那个xxx连接的名字是你在web.xml里进行配置的名字。
      

  11.   

    那楼主要接一个java类然后继承HttpServlet类。实现里面的service方法。在service方法里写你要做的事。
    譬如你先要把网页那边穿过的的数据拿过来是吧:
    String username=request.getParameter("name");
    "name":表示的是你jsp页面中传过来的标签的名字
    例如:
    <td><input name="name" type="text" id="name"/></td>
    这样你输出看看能拿到你页面中传过来的值了。
    System.out.println(name);
    如果楼主会用hibernate的话。可以把这些传过的值封转到你也对象里然后再插入到数据库中就行了。
      

  12.   

    不好意思打错了几个字。
    如果楼主会用hibernate的话。可以把这些传过来的值封装到对象里,然后插入到数据库里就行了。
      

  13.   

    楼主干脆一步到位吧。把JSP+Servlet分页也学学。做小项目能省不少力气。
      

  14.   

    可以用struts,也可以直接用连接,在服务器端接收到后存入数据库。
      

  15.   

    不用那么复杂吧,又是struts  又是hibernate,   jsp就可以了吧 ,form 里面的数据,submit后直接写入数据库就可以了 ,jdbc 就可以实现。
    form 的action属性里面填写你要提交到那个页面,提交到本页也可以,然后在那个页面里接收参数,然后通过JDBC方式写入数据库就可以了
      

  16.   

    个人认为要在input type=text value=""里面填写一些东西,但不知道怎么填写那个VALUE 是文本框里面显示的初始值,不填就是空白