<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*,com.ccniit.bean.*,java.text.*,java.util.*"%>
<!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=UTF-8">
<title>Insert title here</title></head>
<body>
<%
Connection conn = DBUtil.getConn();
String id = request.getParameter("pid");
String sql = "select * from posts,reply where posts.pid=reply.pid and posts.pid=?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, Integer.parseInt(id));
ResultSet rs = pstmt.executeQuery();
if (rs != null) {
while (rs.next()) {
%>
<input type="button" value="发表新帖"
onClick="window.location.href('newPost.jsp')">
<a href="newReply.jsp?pid=<%=rs.getInt("pid")%>">回复</a>
<h3 align="center">帖子浏览</h3>
<table border="1" align="center" width="603" height="10">
<tr align="center">
<td width="123">作者</td>
<td colspan="2">帖子内容</td>
</tr>
<tr>
<td rowspan="2" align="center"><%=rs.getString("pauthor")%></td>
<td width="175">标题:<%=rs.getString("ptitle")%></td>
<td width="283" align="right">发表于:<%=rs.getString("pdate")%></td>
</tr>
<tr>
<td colspan="2" align="center"><textarea name="pcontent" cols=55
rows="6"><%=rs.getString("pcontent")%></textarea>
</td>
</tr>
<tr>
<td rowspan="2" align="center"><%=rs.getString("rauthor")%></td>
<td>标题:<%=rs.getString("rtitle")%></td>
<td align="right">发表于:<%=rs.getString("rdate")%></td>
</tr>
<tr>
<td colspan="2" align="center"><textarea name="pcontent" cols=55
rows="6"><%=rs.getString("rcontent")%></textarea>
</td>
</tr> <%
}
}
DBUtil.closeConnection(conn);
%>
</table>
</body></html>代码如上, sql有了两个表posts主题帖表,reply回复帖表   posts pid是主键,reply pid是外键;
出现的问题,1:如果回复贴中无该主题帖的回复,那从帖子概要浏览跳转过来后,什么都不显示;
            2:如果回复贴中有该主题帖的回复且回复大于2条,那在显示的时候将重复读取一次主题帖内容并显示出来;
怎么解决的,不懂啊