Test site:
Http://www.triaton.com.cn: 1080/examples/tree. jsp
Similar to the msdn csdn navigation tree, JSP + JavaScript!
<! -- Tree. jsp -->
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. util. *;" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>
<Body>
<IFRAME width = "100%" Height = "100" id = "hiddenframe"> </iframe>
<SCRIPT>
Function expandnode (parentnode, parentid ){
VaR nodex = eval (parentnode. ID + '_ 0 ');
If (nodex. style. Display = 'None ')
{
Nodex. style. Display = "Block ";
If (nodex. Loaded = 'no ')
{
Document. Frames ['dendenframework']. Location. Replace ("subtree. jsp? PID = "+ parentid +" & pnode = "+ parentnode. ID );
Nodex. Loaded = 'yes ';
}
}
Else
{
Nodex. style. Display = 'none ';
}
}
</SCRIPT>
<Center>
<Table border = "1" width = "20%" Height = "60%">
<Tr>
<TD>
<Div style = "overflow: auto; width: 100%; Height: 100%">
& Lt; table width = "300%" & gt;
<Tr>
<TD>
<%
Java. Lang. Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
// Java. SQL. connection connectionx = Java. SQL. drivermanager. getconnection ("JDBC: ODBC: Driver = {Microsoft Access Driver (*. MDB)}; DBQ = D: // resin // Doc // examples // tree. mdb "," admin ","");
// Java. SQL. Statement statementx = connectionx. createstatement ();
Java. SQL. resultset resultsetx = Java. SQL. drivermanager. getconnection ("JDBC: ODBC: Driver = {Microsoft Access Driver (*. MDB)}; DBQ = E: // Resin-2.1.6 // Doc // examples // tree. mdb "," admin "," "2.16.createstatement(cmd.exe cutequery (" select *, (select count (*) from tree where parentid = T. ID) as children from tree T where parentid = 0 ");
Int I = 0;
Int children;
Int ID;
While (resultsetx. Next ())
{
Children = resultsetx. getint ("children ");
Id = resultsetx. getint ("ID ");
%>
<Div id = 'node _ <% = I %> '> <a href = '#'
<% IF (Children> 0)
{%>
Onclick = 'pandnode (node _ <% = I %>, <% = ID %>) '> + </a>
<% ;}
Else {%>
>-</A> <% ;}%>
<A href = '#'
<% IF (Children> 0)
{%>
Ondblclick = 'expandnode (node _ <% = I %>, <% = ID %> )'
<% }%>
>
<% = Resultsetx. getstring ("remark") %> </a>
</Div>
<Div id = 'node _ <% = I %> _ 0' style = 'display: none' loaded = 'no'>
& Nbsp; loading...
</Div>
<%
I ++;
}
%>
</Body>
</Html>
<! -- Subtree. jsp -->
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. util. *;" %>
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>
<%
String parentnode = request. getparameter ("pnode ");
Int I;
Int J;
String nspace = "";
J = parentnode. Length ()-parentnode. replaceall ("_", ""). Length ();
For (I = 0; I <j; I ++)
Nspace = nspace + "& nbsp ;";
String shtml = "";
I = 0;
Java. Lang. Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
// Java. SQL. connection connectionx = Java. SQL. drivermanager. getconnection ("JDBC: ODBC: Driver = {Microsoft Access Driver (*. MDB)}; DBQ = D: // resin // Doc // examples // tree. mdb "," admin ","");
// Java. SQL. Statement statementx = connectionx. createstatement ();
Java. SQL. resultset resultsetx = Java. SQL. drivermanager. getconnection ("JDBC: ODBC: Driver = {Microsoft Access Driver (*. MDB)}; DBQ = E: // Resin-2.1.6 // Doc // examples // tree. mdb "," admin "," "2.16.createstatement(cmd.exe cutequery (" select *, (select count (*) from tree where parentid = T. ID) as children from tree T where parentid = "+ request. getparameter ("PID "));
Int children;
Int ID;
While (resultsetx. Next ())
{Children = resultsetx. getint ("children ");
Id = resultsetx. getint ("ID ");
Shtml = shtml + "<Div id = '" + parentnode + "_" + (I + 1) + "'>" + nspace + "<a href = '#'";
If (Children> 0)
Shtml = shtml + "onclick = 'expandnode (" + parentnode + "_" + (I + 1) + "," + ID + ") '> + ";
Else shtml = shtml + "> -";
Shtml = shtml + "</a> // n" + "<a href = '#'";
If (Children> 0)
Shtml = shtml + "ondblclick = 'expandnode (" + parentnode + "_" + (I + 1) + "," + ID + ")'";
Shtml = shtml + ">" + ID + ":" + resultsetx. getstring ("remark") + "</a> </div> ";
If (Children> 0)
Shtml = shtml + "<Div id = '" + parentnode + "_" + (I + 1) + "_ 0' style = 'display: none 'loaded = 'no'> "+ nspace +" & nbsp; loading... </div> ";
%>
<% I ++;
} %>
<Body>
<SCRIPT>
VaR x = eval ('parent. '+' <% = parentnode + "_ 0" %> ');
X. innerhtml = "<% = shtml %> ";
</SCRIPT>
</Body>
</Html>