📄 delete.jsp
字号:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import="java.sql.*"%>
<%
String strlog = (String)session.getAttribute("admin");
if(strlog == null || !strlog.equals("true")){
out.println("<center>对不起请先登录"+"<br><a href=Login.jsp>管理员登录</a></center>");
return;
}
%>
<%!
private void del(Connection conn,int id){
Statement st = null;
ResultSet rs = null;
try{
st = conn.createStatement();
String sql = "select * from article where pid = " + id;
rs = st.executeQuery(sql);
while(rs.next()) {
del(conn, rs.getInt("id"));
}
st.executeUpdate("delete from article where id=" + id);
}catch(SQLException e){
System.out.println("系统找不到指定数据库");
}
try{
if(rs != null){
rs.close();
rs = null;
}
if(st != null){
st.close();
st = null;
}
}catch(SQLException e){
System.out.println("数据库已经关闭");
}
}
%>
<%
int id = Integer.parseInt(request.getParameter("id"));
int pid = Integer.parseInt(request.getParameter("pid"));
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mySQL://localhost/bbs?user=root&password=yuanshuai");
Statement st = conn.createStatement();
conn.setAutoCommit(false);
del(conn,id);
ResultSet rs = st.executeQuery("select count(*) from article where id=" + pid);
rs.next();
int count = rs.getInt(1);
if(count <= 0){
st.executeUpdate("update article set isleaf=0 where id=" + pid);
}
conn.commit();
conn.setAutoCommit(true);
try{
if(st != null){
st.close();
st = null;
}
if(conn != null){
conn.close();
conn = null;
}
}catch(SQLException e){
System.out.println("数据库已经关闭");
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>删除页面</title>
</head>
<body>
<div align="center">
<font size=6 color="red"><br>恭喜你!</font><br><br>
<font size=6 color="red">内容已经成功删除</font><br><br>
<a href="ShowArticalTree.jsp">返回</a>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -