<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ page import="java.sql.*,java.util.regex.Pattern"%> 帖子详情 <% if (session.getAttribute("actualuser") == null) { out.println( ""); return; } Object user0 = session.getAttribute("actualuser"); /* out.println("欢迎"+user0);//输出当前session用户 */ %> <% String k1 = request.getQueryString();//得到ID的值(id=数字). String re = "\\D+"; //正则表达式 String result = k1.replaceAll(re, ""); //找到不是数字的字符,用""替代 %> <%@ include file="module/top.jsp"%>
<%@ include file="module/sidebar.jsp"%>

帖子详情

<% String id = request.getParameter("id"); String username = ""; Connection con; Statement sql; ResultSet rs; String content = ""; String regex = "<(?!image).*?>"; try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { out.print("驱动异常"); } con = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs?useUnicode=true&characterEncoding=utf-8", "root", ""); sql = con.createStatement(); String send = null; content = "select subject,content,time,flag,username from send where id = '" + request.getParameter("id") + "'"; rs = sql.executeQuery(content); while (rs.next()) { %> <% if (!adminuser.equals("")) { %> <% if (rs.getInt("flag") == 0) { %> <% } else { %> <% } %> <% } else { out.print(""); } %>

<% if (rs.getInt("flag") == 1 && rs.getString("subject").matches(regex)) { //置顶且匹配 %> 主题: <% } if (rs.getInt("flag") == 0 && rs.getString("subject").matches(regex)) { //不置顶但匹配 %> 主题: <% } if (rs.getInt("flag") == 1 && !(rs.getString("subject").matches(regex))) { //置顶但不匹配 %> 主题: <% } if (rs.getInt("flag") == 0 && !(rs.getString("subject").matches(regex))) { //不置顶且不匹配 %> 主题: <%=rs.getString("subject")%> <%} %>

内容

<%if(rs.getString("content").matches(regex)) {%> <% }else{ %> <%=rs.getString("content")%> <%} %>
<%=username%> <%=rs.getDate("time")%> <%=rs.getTime("time")%>
<% } sql.close(); rs.close(); con.close(); %>

评论信息

<% int floor = 1; Connection comcon; Statement comsql; ResultSet comrs; try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { out.print("驱动异常"); } comcon = DriverManager.getConnection("jdbc:mysql://localhost/db_bbs", "root", ""); comsql = comcon.createStatement(); String comment = null; comment = "select commentid,comment,time,username from comment where subid = (select id from send where id ='" + id + "')"; comrs = comsql.executeQuery(comment); try { while (comrs.next()) { %>
<% if (!adminuser.equals("")) { %> " role="button"> <% } else { out.print(""); } %> <%if(comrs.getString("comment").matches(regex)) {%> <% }else{ %> <%=comrs.getString("comment")%> <%} %>
<%=floor++%>楼 <%=comrs.getString("username")%> <%=comrs.getDate("time")%> <%=comrs.getTime("time")%>
<% } } catch (Exception e) { out.print("无法显示评论信息"); } comsql.close(); comrs.close(); comcon.close(); %>




>

评论

<%@ include file="module/footer.jsp"%>