index.jsp
上传用户:shjgzm
上传日期:2017-08-31
资源大小:2757k
文件大小:2k
源码类别:

Ajax

开发平台:

Java

  1. <%@ page contentType="text/html; charset=UTF-8"%>
  2. <%@ page language="java"%>
  3. <%@ page import="java.sql.*,ajax.db.DBUtils"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-type" content="text/html; charset=utf-8">
  8. <script type="text/javascript" src="bbs.js"></script>
  9. <link href="bbs.css" type="text/css" rel="stylesheet">
  10. <title>无刷新显示回帖</title>
  11. </head>
  12. <body>
  13. <h1>无刷新显示回帖</h1>
  14. <div id="statusDiv" style="display:none"></div>
  15. <div id="thread">
  16. <%
  17.     String sql = "select * from bbs_post where threadid = 1 order by id asc";   //定义查询数据库的SQL语句
  18.     Connection conn = null;                 //声明Connection对象
  19.     PreparedStatement pstmt = null;         //声明PreparedStatement对象
  20.     ResultSet rs = null;                    //声明ResultSet对象
  21.     try {
  22.         conn = DBUtils.getConnection();     //获取数据库连接
  23.         pstmt = conn.prepareStatement(sql); //根据sql创建PreparedStatement
  24.         rs = pstmt.executeQuery();          //执行查询,返回结果集
  25.         while (rs.next()) {
  26.             %>
  27.             <div class="post" id="post<%=rs.getString("id")%>">
  28.                 <div class="post_title"><%=rs.getString("title")%> [<%=rs.getString("username")%>]</div>
  29.                 <div class="post_content"><pre><%=rs.getString("content")%></pre></div>
  30.             </div>
  31.             <%
  32.         }
  33.     } catch (SQLException e) {
  34.         System.out.println(e.toString());
  35.     } finally {
  36.         DBUtils.close(rs);                  //关闭结果集
  37.         DBUtils.close(pstmt);               //关闭PreparedStatement
  38.         DBUtils.close(conn);                //关闭连接
  39.     }
  40. %>
  41. </div>
  42. <table class="reply">
  43. <tr>
  44.     <td colspan="2" class="title">回帖<input type="hidden" name="threadid" id="threadid" value="1"></td>
  45. </tr>
  46. <tr>
  47.     <td>姓名:</td>
  48.     <td><input type="text" name="username" id="username"></td>
  49. </tr>
  50. <tr>
  51.     <td>标题:</td>
  52.     <td><input type="text" name="post_title" id="post_title"></td>
  53. </tr>
  54. <tr>
  55.     <td>内容:</td>
  56.     <td><textarea name="post_content" id="post_content"></textarea></td>
  57. </tr>
  58. <tr>
  59.     <td colspan="2"><input type="button" onclick="submitPost()" value="提交"></td>
  60. </tr>
  61. </table>
  62. </body>
  63. </html>