📄 post.jsp
字号:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="java.sql.*" %>
<%
if(request.getParameter("action").equals("post"))
{
request.setCharacterEncoding("gbk");
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?useUnicode=true&characterEncoding=gbk";
Connection conn=DriverManager.getConnection(url,"root","12345");
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>
<title>My JSP 'post.jsp' starting page</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<table>
<form action="post.jsp" method="post">
<input type="hidden" name="action" value="post">
<tr>
<td>
<input type="text" name="title">
</td>
</tr>
<tr>
<td>
<textarea cols="50" row="10" name="cont"></textarea>
</td>
</tr>
<tr colspan="2">
<td>
<input type="submit" value="reply">
</td>
</tr>
</form>
</table>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -