zoukankan      html  css  js  c++  java
  • [BBS] ReplyOK.jsp 04

    <%@ page language="java" contentType="text/html; charset=GBK"
        pageEncoding="GBK"%>
    <%@ page import="java.sql.*"%>
    
    <%
        request.setCharacterEncoding("gbk"); // 解决进入数据库的乱码问题
    
        int id = Integer.parseInt(request.getParameter("id"));
        int rootId = Integer.parseInt(request.getParameter("rootid"));
        String title = request.getParameter("title");
    
        if (title == null) {
            out.println("error! please use my bbs in the right way!");
            return;
        }
    
        title = title.trim();
    
        if (title.equals("")) {
            out.println("title could not be empty!");
            return;
        }
    
        String cont = request.getParameter("cont");
        cont = cont.trim();
    
        if (cont.equals("")) {
            out.println("content could not be empty!");
            return;
        }
    
        cont = cont.replaceAll("
    ", "<br>");
    
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
        Connection conn = DriverManager.getConnection(url);
    
        conn.setAutoCommit(false);
    
        String sql = "insert into article values (null, ?, ?, ?, ?, now(), 0)";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        Statement stmt = conn.createStatement();
    
        pstmt.setInt(1, id);
        pstmt.setInt(2, rootId);
        pstmt.setString(3, title);
        pstmt.setString(4, cont);
        pstmt.executeUpdate();
    
        stmt.executeUpdate("update article set isleaf = 1 where id = " + id);
    
        conn.commit();
        conn.setAutoCommit(true);
    
        stmt.close();
        pstmt.close();
        conn.close();
    
        response.sendRedirect("ShowArticleTree.jsp");
    %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GBK">
    <title>Insert title here</title>
    </head>
    <body>
        <font color="red" size="7"> OK! </font>
    </body>
    </html>
    


  • 相关阅读:
    JavaWeb-对象增强的方式
    JavaWeb-dbcp连接池
    eclipse发送音频等大数据包到数据库的异常解决方案
    JDBC-prepareStatement预编译
    JDBC原理
    JDBC入门
    当我们说前端,我们在说什么?
    markdown上下左右,跳至行尾行首,重设快捷键
    web API简介(四):客户端储存之IndexedDB API
    过年搭出租车攻略
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786848.html
Copyright © 2011-2022 走看看