Algorithms for implementing the Forum tree structure without Recursion

Source: Internet
Author: User

<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 ("display Forum tree structure ");
Out. print ("<br> ");
Try {
String SQL = "select * from mybbslist order by rootid desc, depth, fid, bbsid ";
ResultSet rs = mybbs.exe cuteQuery (SQL );
If (rs. next ())
{
Rs. last ();
IntRowCount = rs. getRow ();
Out. print ("in the Forum Tree ");
Out. print (intRowCount );
Out. print ("leaf nodes ");
Rs. first ();
Int j = 0;
Int Depth = 0;
Out. print ("<ul> ");
While (j <intRowCount)
{
Int rsDepth = rs. getInt ("Depth ");
If (rsDepth <Depth)
{
For (int I = 1; I <Depth + 1; I = I + 1)
{
Out. print ("</ul> ");
}
}
RsDepth = 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 ");
J = j + 1;
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 the mysql connection
Try {
If (! Mybbs. closeConn ());
} Catch (Exception ex ){
System. err. println ("closeConn:" + ex. getMessage ());
}
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.