Jsp+javascript implement a similar MSDN CSDN navigation tree Effect

Source: Internet
Author: User
Tags count eval generator implement odbc sql string access
javascript|js| Navigation

<!--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= "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[' Hiddenframe '].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% ">
<table width= "300%" >
<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)};D Bq=d:\\resin\\doc\\examples\\tree\\tree.mdb "," admin "," ");
Java.sql.Statement Statementx = Connectionx.createstatement ();
Java.sql.ResultSet resultsetx = java.sql.DriverManager.getConnection ("Jdbc:odbc:driver={microsoft Access driver (*. MDB)};D bq=e:\\resin-2.1.6\\doc\\examples\\tree\\tree.mdb "," admin "," ""). Createstatement (). ExecuteQuery ("SELECT *, (SELECT COUNT (*) from the 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)
{%>

<%}%>
>
<%=resultsetx.getstring ("remark")%></a>
</div>

<div id= ' node_<%= i%>_0 ' style= ' display:none ' loaded= ' no ' >
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 + "";
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)};D Bq=d:\\resin\\doc\\examples\\tree\\tree.mdb "," admin "," ");
Java.sql.Statement Statementx = Connectionx.createstatement ();
Java.sql.ResultSet resultsetx = java.sql.DriverManager.getConnection ("Jdbc:odbc:driver={microsoft Access driver (*. MDB)};D bq=e:\\resin-2.1.6\\doc\\examples\\tree\\tree.mdb "," admin "," ""). Createstatement (). ExecuteQuery ("SELECT *, (SELECT COUNT (*) from the 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 + "is Load ...</div> ";
%>
<% i++;
}%>
<BODY>
<script>
var x = eval (' parent. ' + ' <%= parentnode + ' _0 '%> ');
X.innerhtml= "<%= SHTML%>";
</script>
</BODY>
</HTML>



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.