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>
    


  • 相关阅读:
    codeforces 439C 模拟
    codeforces 435B
    【WebVR】AFrame中的A-sky无法利用src指定路径显示全景图
    【UE4】添加头文件之后VS中UCLASS()报错问题解决办法
    【UE4】蓝图之间的通讯
    git中报unable to auto-detect email address 错误的解决办法
    2017ACM省赛总结与生涯回顾
    hihocoder#1121 : 二分图一•二分图判定
    hihocoder#1039 : 字符消除
    2048low版
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786848.html
Copyright © 2011-2022 走看看