JSP实现论坛树型结构的具体算法
实现论坛树型结构的算法很多,具体你可以去www.chinaasp.com的全文搜索中查询。我现在的JSP论坛采用的也是当中的一种:不用递归实现树型结构的算法,现在我将论坛树型结构的具体算法和大家介绍一下,和大家一起交流。
1、演示表的结构:
表名:mybbslist
字段 数据类型 说明
BBSID 自动编号
RootID Int 根帖ID,本身为根帖则RootID = ID
FID Int 父帖ID,上一层帖子的ID,如是根帖则FID = 0
DEPTH Int 根帖Level=0,其他依据回复的深度递增
BBSSubject Char 主题
2。创建表:
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、连接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: "
相关文档:
Login.java
/******************************************************/
注意:由于在jsp中创建Cookie时,必须保证Cookie创建语句写在jsp页面头部的<jsp:include page="includes\head.jsp" flush="true" />标签之前才会生效,否则手动添加的Cookie失败。
所以我决定讲创建Cookie语句放在servl ......
如果在自订标签库时,并不需要对标签本体作处理,则您可以继承TagSupport类别,TagSupport类别实作了Tag与 IterationTag介面,IterationTag介面则是Tag介面的子介面,TagSupport类别替您预先实作了这两个介面中的方法,在继承TagSupport之后,您视需要来改写当中的一些方法(这是 Default Adapter模式)。
Tag介面中与标签 ......
JSP语法
指令(Directive)标记
page 指令
include 指令
taglib 指令
<%@ page language="java" %>
<%@ include file="test.html"%>
<%@ taglib uri="http://www.deng.com/tags" prefix="util" %>
......