简单BBS回复帖子页面。。回复内容提交不到数据库?求老师指点
简单BBS回复帖子页面。。回复内容提交不到数据库?提交上去的是空的
这 是我的代码:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<%
request.setCharacterEncoding("gbk");
try{
int id=Integer.parseInt(request.getParameter("id"));
System.out.print("id");
int rootid= Integer.parseInt(request.getParameter("rootid"));
String title= request.getParameter("title");
String cont = request.getParameter("cont");
cont = cont.replaceAll("\n","<br>");
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=admin";
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();
}catch(NumberFormatException e){
e.getStackTrace();
}
response.sendRedirect("ShowArticle.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>
</body>
</html>