In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to achieve the JSP forum tree structure of the specific algorithm, I believe that most people do not understand, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
1. The structure of the demonstration table of the JSP Forum:
Table name: mybbslist field data type indicates that BBSID automatically numbers RootID Int root post ID. If it is a root post, RootID = ID FID Int parent post ID, ID of the previous post, if root post, FID = 0 DEPTHInt root post Level=0, other BBSSubject Char topics are incremented according to the depth of reply.
2. The creation table of JSP Forum:
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. Implementation of JSP Forum BEAN for connecting to MYSQL database
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 (rsgiving null) rs.close (); if (stmtshipping null) stmt.close () If (connexual null) conn.close (); return true;} catch (SQLException ex) {System.err.println ("closeConn:" + ex.getMessage ()); return false;}
4. Display of the JSP forum the JavaScript/ "target=" _ blank "> JSP program of the forum
< 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 ("Show forum tree"); 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 ("in the forum tree"); out.print (intRowCount); out.print ("leaf node"); rs.first (); int jacqu0; int Depth= 0; out.print ("< ul >"); while (j < intRowCount) {int rsrsDepth=rs.getInt ("Depth") If (rsDepth < Depth) {for (int iTunes 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"); Rs.next ();} out.print ("< / ul >");} else {out.print ("No record in database");}} catch (SQLException E) {out.println ("SQLException:" + E.getMessage ()); out.println ("SQLState:" + E.getSQLState ()); out.println ("VendorError:" + E.getErrorCode ()) }% > <% / close mysql connection try {if (! mybbs.closeConn ());} catch (Exception ex) {System.err.println ("closeConn:" + ex.getMessage ());}% > above are all the contents of this article entitled "how to implement the concrete algorithm of JSP Forum Tree structure". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.