📄 show_post.jsp
字号:
<%@ page language="java" contentType="text/html; charset=GBK"
pageEncoding="GBK"%>
<%@page import="java.util.*,java.io.*,java.sql.*"%>
<%@ include file="conn.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>查看帖子</title>
</head>
<body>
<!-- 载入页头 -->
<jsp:include page="./include/top.jsp"></jsp:include>
<%
String Referer = "";
if (null != request.getHeader("Referer")) {
Referer = request.getHeader("Referer");
%>
<a href="<%=Referer%>">返回上一页</a>
<%
} else {
%>
<a href="index.jsp">返回主页</a>
<br>
<%
}
%>
<%
String username = "";
String pageno = "1";
if (null != session.getAttribute("login")
|| (null != session.getAttribute("adminlogin"))) {
if (null != session.getAttribute("login"))
username = session.getAttribute("login").toString();
String id = "";
//接收帖子id参数
if (null != request.getParameter("id")) {
id = request.getParameter("id").toString();
if (null != request.getParameter("pageno"))
if (0 < Integer
.parseInt(request.getParameter("pageno")))
pageno = request.getParameter("pageno");
else
pageno = "1";
else
pageno = "1";
try {
String author = "";
String title = "";
String content = "";
String dnt = "";
String strDo = "";
strDo = "SELECT * FROM " + tbbs + " WHERE id='" + id
+ "'";
System.out.print(strDo + "\n");
rs = stmt.executeQuery(strDo);
if (rs.next()) {
author = rs.getString("author");
title = rs.getString("title");
content = rs.getString("content");
dnt = rs.getString("dnt");
}
//字符过滤&处理
title = title.replaceAll("&sd", "'");
title = title.replaceAll("&dd", "\"");
content = content.replaceAll("&sd", "'");
content = content.replaceAll("&dd", "\"");
content = content.replaceAll("\n", "<br/>");
//标题字符过长切换
if (title.length() > 20)
title = title.substring(0, 17) + "...";
//自动换行
String tmpcontent = "";
int ilength = content.length();
if (ilength > 65) {
while (ilength > 65) {
tmpcontent += content.substring(0, 65)
+ "<br/>";
ilength -= 65;
}
if (tmpcontent.length() - ilength > 0)
tmpcontent += content.substring((content
.length() - ilength), content.length());
} else {
tmpcontent = content;
}
rs.close();
%>
<br>
<br>
标题:<%=title%>
<%
System.out.print("author=" + author + " username="
+ username + "\n");
if (author.equals(username)) {
out.print("<a href='edit_post.jsp?id=" + id
+ "'>编辑帖子</a>");
}
%>
<br>
<br>
作者:<%=author%>
发布时间:<%=dnt%>
<br>
<br>
<%=tmpcontent%>
<br>
<br>
<%
out.print("<a href='reply_post.jsp?postid=" + id
+ "'>回复帖子</a>");
%>
<br>
<br>
<%
//取得帖子回复数据
try {
String replyid = "";
String replytitle = "";
String replyauthor = "";
int replyauthorid = 0;
String replycontent = "";
String replydnt = "";
//取得rs的个数
int count = 0;
strDo = "SELECT COUNT(*) FROM " + treply
+ " WHERE postid='" + id + "'";
rs = stmt.executeQuery(strDo);
if (rs.next()) {
count = rs.getInt(1);
System.out.println("count=" + count);
//查询帖子回复
if (pageno.equals("1")) {
strDo = "SELECT * FROM "
+ treply
+ " WHERE postid='"
+ id
+ "' "
+ " LIMIT "
+ String.valueOf(Integer
.parseInt(pageno) * 10);
} else {
strDo = "SELECT * FROM "
+ treply
+ " WHERE postid='"
+ id
+ "' "
+ " LIMIT "
+ String
.valueOf(Integer
.parseInt(pageno) * 10 - 10)
+ " , "
+ String.valueOf(Integer
.parseInt(pageno) * 10);
}
System.out.print(strDo + "\n");
rs = stmt.executeQuery(strDo);
while (rs.next()) {
replyid = String.valueOf(rs.getInt("id"));
replytitle = rs.getString("title");
replyauthor = rs.getString("author");
replyauthorid = rs.getInt("authorid");
replycontent = rs.getString("content");
replydnt = rs.getString("dnt");
//字符过滤&处理
replytitle = replytitle.replaceAll("&sd",
"'");
replytitle = replytitle.replaceAll("&dd",
"\"");
replycontent = replycontent.replaceAll(
"&sd", "'");
replycontent = replycontent.replaceAll(
"&dd", "\"");
replycontent = replycontent.replaceAll(
"\n", "<br/>");
//显示回复
out.print("<br><hr>");
//标题字符过长切换
if (replytitle.length() > 20)
replytitle = replytitle
.substring(0, 17)
+ "...";
out.print("回复标题:" + replytitle);
if (null != session
.getAttribute("adminlogin")) {
out
.print(" "
+ "<a href='./admin/admin_edit_reply.jsp?id="
+ replyid
+ "'>修改回复</a>"
+ " ");
out
.print("<a href='./admin/admin_del_reply.jsp?id="
+ replyid
+ "'>删除回复</a>");
} else {
if (replyauthor.equals(username)) {
out
.print(" "
+ "<a href='edit_reply.jsp?id="
+ replyid
+ "'>修改回复</a>"
+ " ");
}
}
out.print("");
out.print("<br><br>");
out
.print("回复作者:<a href='show_profile.jsp?authorid="
+ String
.valueOf(replyauthorid)
+ "'>"
+ replyauthor
+ "</a>");
out.print(" 回复时间:" + replydnt);
out.print("<br><br>");
//自动换行
String tmpreplycontent = "";
int ireplylength = content.length();
if (ilength > 65) {
while (ilength > 65) {
tmpreplycontent += replycontent
.substring(0, 65)
+ "<br/>";
ireplylength -= 65;
}
if (tmpreplycontent.length()
- ireplylength > 0)
tmpreplycontent += replycontent
.substring(
(replycontent
.length() - ireplylength),
replycontent
.length());
} else {
tmpreplycontent = replycontent;
}
out.print(tmpreplycontent);
out.print("<br><br>");
}
rs.close();
//翻页链接
if (!pageno.equals("1")) {
if (!pageno.equals("1")) {
out
.print("<br><br><a href='show_post.jsp?id="
+ id
+ "&pageno="
+ String
.valueOf(Integer
.parseInt(pageno) - 1)
+ "'>查看上一页回复</a>");
}
out.print(" ");
}
if (count > (Integer.parseInt(pageno) * 10)) {
out.print("<a href='show_post.jsp?id="
+ id
+ "&pageno="
+ String.valueOf(Integer
.parseInt(pageno) + 1)
+ "'>查看下一页回复</a><br><br>");
}
}
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("error.jsp");
}
out.print("<br><br>");
} catch (Exception e) {
e.printStackTrace();
response.sendRedirect("error.jsp");
} finally {
stmt.close();
conn.close();
}
} else {
response.sendRedirect("error.jsp");
}
} else {
response.sendRedirect("error.jsp");
}
%>
<%
if (null != request.getHeader("Referer")) {
Referer = request.getHeader("Referer");
%>
<a href="<%=Referer%>">返回上一页</a>
<%
} else {
%>
<a href="index.jsp">返回主页</a>
<br>
<%
}
%>
<!-- 载入页尾 -->
<jsp:include page="./include/foot.jsp"></jsp:include>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -