简单BBS回复帖子页面。。回复内容提交不到数据库?求老师指点

有猿千里来相会 2011-11-07 03:34:12
简单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>
...全文
50 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzc543806053 2011-11-07
  • 打赏
  • 举报
回复
还没开始学

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧