您好,登錄后才能下訂單哦!
小編給大家分享一下如何實現JSP論壇樹型結構的具體算法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
1、JSP論壇之演示表的結構:
表名:mybbslist 字段 數據類型說明 BBSID自動編號 RootID Int 根帖ID,本身為根帖則RootID = ID FID Int 父帖ID,上一層帖子的ID,如是根帖則FID = 0 DEPTHInt 根帖Level=0,其他依據回復的深度遞增 BBSSubject Char主題
2、JSP論壇之創建表:
create table mybbslist ( forumID int(20) not null, bbsID int auto_increment primary key, rootid int(20) not null, fid int(20) not null, depth int(20) not null, userID int(20) not null, bbsUser varchar(24) not null, bbsSubject varchar(100) not null, bbsContent text, bbsTime varchar(30), bbsRead int(20), bbsReply int(20), INDEX forumID (forumID))
3、JSP論壇之實現連接MYSQL數據庫的BEAN
package netzero; import java.sql.*; public class mydb { String driverName = "org.gjt.mm.mysql.Driver"; Connection conn = null; Statement stmt = null; ResultSet rs = null; String connURL= "jdbc:mysql://localhost/mybbs?user=root&password=how&useUnicode=true&characterEncode=8859_1"; //String connURL= "jdbc:mysql://localhost/netzerobbs?user=root&password=how"; public mydb() { try { Class.forName(driverName); } catch (java.lang.ClassNotFoundException e) { System.err.println("netzero(String): " + e.getMessage()); } } public ResultSet executeQuery(String sql) throws SQLException { conn = DriverManager.getConnection(connURL); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); return rs; } public boolean closeConn() { try { if (rs!=null) rs.close(); if (stmt!=null) stmt.close(); if (conn!=null) conn.close(); return true; } catch ( SQLException ex ) { System.err.println("closeConn: " + ex.getMessage()); return false; } } }
4、JSP論壇的之顯示論壇的JavaScript/" target="_blank">JSP程序
﹤jsp:useBean id="mybbs" scope="session" class="netzero.mydb" /﹥ ﹤%@ page contentType="text/html;charset=gb2312" %﹥ ﹤%@ page import="java.io.*" %﹥ ﹤%@ page import="java.sql.*" %﹥ ﹤% int intRowCount; out.print("顯示論壇樹形結構"); out.print("﹤br﹥﹤br﹥"); try { String sql="select * from mybbslist order by rootid desc,depth,fid,bbsid"; ResultSet rs = mybbs.executeQuery(sql); if (rs.next()) { rs.last(); intRowCount=rs.getRow(); out.print("論壇樹中有"); out.print(intRowCount); out.print("個葉子節點"); rs.first(); int j=0; int Depth = 0; out.print("﹤ul﹥"); while(j﹤intRowCount) { int rsrsDepth=rs.getInt("Depth"); if (rsDepth﹤Depth) { for(int i=1;i﹤Depth+1;ii=i+1) { out.print("﹤/ul﹥"); } } rsrsDepth=rs.getInt("Depth"); if (rsDepth﹥Depth) { out.print("﹤ul﹥"); } out.print("﹤li﹥"); String bbssubject=rs.getString("bbssubject"); out.print(bbssubject); out.print("﹤/li﹥"); Depth = rs.getInt("Depth"); jj=j+1; rs.next(); } out.print("﹤/ul﹥"); } else { out.print("數據庫中無記錄"); } }catch (SQLException E) { out.println("SQLException: " + E.getMessage()); out.println("SQLState: " + E.getSQLState()); out.println("VendorError: " + E.getErrorCode()); } %﹥ ﹤% //關閉mysql連接 try { if(!mybbs.closeConn()); } catch (Exception ex) { System.err.println("closeConn: " + ex.getMessage()); } %﹥
以上是“如何實現JSP論壇樹型結構的具體算法”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。