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>
    


  • 相关阅读:
    Spring Boot 自定义 Banner 教程
    Spring Boot 操作 Excel
    Spring Boot 文件上传简易教程
    SpringMVC 处理请求的整个流程?入口?
    实现单例模式的9个方法
    Mybatis Generator最完整配置详解
    接口限流
    添加jar包到本地Maven仓库
    Java ConcurrentModificationException异常原因和解决方法
    RESTful API 设计指南[转]
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786848.html
Copyright © 2011-2022 走看看