⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 post.jsp

📁 对于JAVA开发者来说
💻 JSP
字号:
<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<%@ page import="java.sql.*" %>

<%
request.setCharacterEncoding("gbk");
String action = request.getParameter("action");

if(action != null && action.equals("post")) {
	String title = request.getParameter("title");
	String cont = request.getParameter("cont");
	
	cont = cont.replaceAll("\n" , "<br>");
	
	Class.forName("com.mysql.jdbc.Driver");
	Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/bbs?user=root&password=yuanshuai");
	
	conn.setAutoCommit(false);
	
	PreparedStatement pstmt = conn.prepareStatement("insert into article values (null, 0, ?, ?, ?, now(), 0)", Statement.RETURN_GENERATED_KEYS);
	Statement stmt = conn.createStatement();
	
	pstmt.setInt(1, -1);
	pstmt.setString(2, title);
	pstmt.setString(3, cont);
	pstmt.executeUpdate();
	
	ResultSet rsKey = pstmt.getGeneratedKeys();
	rsKey.next();
	int key = rsKey.getInt(1);
	rsKey.close();
	stmt.executeUpdate("update article set rootid = " + key + " where id = " + key);
	
	conn.commit();
	conn.setAutoCommit(true);
	
	stmt.close();
	pstmt.close();
	conn.close();
	
	response.sendRedirect("ShowArticleTree.jsp");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>发表新贴</title>
</head>
<div align="center"><font color="blue" size="6">请填写你要发表的新贴</font></div>
<body>
<form action="Post.jsp" method="post" name="form1">
<div align="center">
<input type="hidden" name="action" value="post">
<font color="red">标题:</font><input type="text" name="title" size="80"><br><br>
<font color="green">内容:</font><textarea rows="12" cols="80" name="cont"></textarea><br>
<input type="submit" name="submit" value="提交">
<input type="reset" name="reset" value="重置">
</div>
</form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -