Div tree: client_tree.jsp
Clienttreereader. Java
1. servlet:
/**
* Recursively reads the distributor tree.
* @ Author Administrator
*
*/
Public class clienttreereader {
Private stringbuffer sbtreehtml = new stringbuffer ();
/**
* Returns an HTML string.
* @ Return
*/
Public String getclienttreehtmlstring (){
Connection conn = NULL;
Try {
Conn = dbutil. getconnection ();
Readclienttree (Conn, 0, 0 );
} Catch (exception e ){
E. printstacktrace ();
} Finally {
Dbutil. Close (conn );
}
Return sbtreehtml. tostring ();
}
///**
// * Recursively read the distributor tree
//*
// * Step 1: Read the distributor tree structure in the simplest way and display it in the browser.
// * @ Param Conn
// * @ Param ID
// * @ Param level control level
//*/
// Private void readclienttree (connection Conn, int ID, int level)
// Throws sqlexception {
// String SQL = "select * From t_client where pid =? ";
// Preparedstatement pstmt = NULL;
// Resultset rs = NULL;
// Try {
// Pstmt = conn. preparestatement (SQL );
// Pstmt. setint (1, ID );
// Rs = pstmt.exe cutequery ();
// While (Rs. Next ()){
// Sbtreehtml. append (Rs. getstring ("name "))
//. Append ("<br> \ n ");
// If ("N". Equals (Rs. getstring ("is_leaf "))){
// Readclienttree (Conn, Rs. getint ("ID"), level );
//}
//}
//} Finally {
// Dbutil. Close (RS );
// Dbutil. Close (pstmt );
//}
//}
///**
// * Recursively read the distributor tree
//*
// * Step 2: Add a sense of attention
// * @ Param Conn
// * @ Param ID
// * @ Param level control level
//*/
// Private void readclienttree (connection Conn, int ID, int level)
// Throws sqlexception {
// String SQL = "select * From t_client where pid =? ";
// Preparedstatement pstmt = NULL;
// Resultset rs = NULL;
// Try {
// Pstmt = conn. preparestatement (SQL );
// Pstmt. setint (1, ID );
// Rs = pstmt.exe cutequery ();
// While (Rs. Next ()){
// For (INT I = 0; I <level; I ++ ){
// Sbtreehtml. append ("& nbsp ;");
//}
// Sbtreehtml. append (Rs. getstring ("name "))
//. Append ("<br> \ n ");
// If ("N". Equals (Rs. getstring ("is_leaf "))){
// Readclienttree (Conn, Rs. getint ("ID"), level + 1 );
//}
//}
//} Finally {
// Dbutil. Close (RS );
// Dbutil. Close (pstmt );
//}
//}
///**
// * Recursively read the distributor tree
//*
// * Step 3: Add a "-" before the leaf node, and add a "+" before the non-leaf node
// * @ Param Conn
// * @ Param ID
// * @ Param level control level
//*/
// Private void readclienttree (connection Conn, int ID, int level)
// Throws sqlexception {
// String SQL = "select * From t_client where pid =? ";
// Preparedstatement pstmt = NULL;
// Resultset rs = NULL;
// Try {
// Pstmt = conn. preparestatement (SQL );
// Pstmt. setint (1, ID );
// Rs = pstmt.exe cutequery ();
// While (Rs. Next ()){
// For (INT I = 0; I <level; I ++ ){
// Sbtreehtml. append ("& nbsp ;");
//}
// If ("N". Equals (Rs. getstring ("is_leaf "))){
// Sbtreehtml. append ("+ ")
//. Append (Rs. getstring ("name "))
//. Append ("<br> \ n ");
// Readclienttree (Conn, Rs. getint ("ID"), level + 1 );
//} Else {
// Sbtreehtml. append ("-")
//. Append (Rs. getstring ("name "))
//. Append ("<br> \ n ");
//}
//}
//} Finally {
// Dbutil. Close (RS );
// Dbutil. Close (pstmt );
//}
//}
/**
* Recursively read the distributor tree
*
* Step 4: Use Div to generate a Tree Structure
* @ Param Conn
* @ Param ID
* @ Param level control level
*/
Private void readclienttree (connection Conn, int ID, int level)
Throws sqlexception {
String SQL = "select * From t_client where pid =? ";
Preparedstatement pstmt = NULL;
Resultset rs = NULL;
Try {
Pstmt = conn. preparestatement (SQL );
Pstmt. setint (1, ID );
Rs = pstmt.exe cutequery ();
While (Rs. Next ()){
Sbtreehtml. append ("<div> ");
Sbtreehtml. append ("\ n ");
For (INT I = 0; I <level; I ++ ){
Sbtreehtml. append (" ");
Sbtreehtml. append ("\ n ");
}
// If ("N". Equals (Rs. getstring ("is_leaf "))){
If (constants. No. Equals (Rs. getstring ("is_leaf "))){
Sbtreehtml. append (" ");
Sbtreehtml. append ("\ n ");
Sbtreehtml. append (" ");
Sbtreehtml. append ("\ n ");
Sbtreehtml. append ("<a href = \" client_node_crud.jsp? Id = "+ Rs. getint ("ID") + "\" target = \ "clientdispareaframe \"> "+ Rs. getstring ("name") + "</a> ");
Sbtreehtml. append ("\ n ");
Sbtreehtml. append ("<Div style = \" display: none; \ "id = \" Div "+ Rs. getint (" ID ") +" \ "> ");
Sbtreehtml. append ("\ n ");
Readclienttree (Conn, Rs. getint ("ID"), level + 1 );
Sbtreehtml. append ("</div> ");
Sbtreehtml. append ("\ n ");
} Else {
Sbtreehtml. append (" ");
Sbtreehtml. append ("\ n ");
Sbtreehtml. append (" ");
Sbtreehtml. append ("\ n ");
// If ("Y1". Equals (Rs. getstring ("is_client "))){
If (constants. Yes. Equals (Rs. getstring ("is_client "))){
Sbtreehtml. append ("<a href = \" client_crud.jsp? Id = "+ Rs. getint ("ID") + "\" target = \ "clientdispareaframe \"> "+ Rs. getstring ("name") + "</a> ");
} Else {
Sbtreehtml. append ("<a href = \" client_node_crud.jsp? Id = "+ Rs. getint ("ID") + "\" target = \ "clientdispareaframe \"> "+ Rs. getstring ("name") + "</a> ");
}
Sbtreehtml. append ("\ n ");
}
Sbtreehtml. append ("</div> ");
Sbtreehtml. append ("\ n ");
}
} Finally {
Dbutil. Close (RS );
Dbutil. Close (pstmt );
}
}
2. jsp: (eval in JS is used to convert objects into JS objects or expressions)
<Script language = "JavaScript">
<! --
Function display (ID ){
Eval ("Var DIV = div" + id );
Eval ("Var IMG = IMG" + id );
Eval ("Var im = im" + id );
Div. style. Display = div. style. Display = "block "? "None": "Block ";
IMG. src = div. style. Display = "block "? "../Images/minus.gif": "../images/plus.gif ";
Im. src = div. style. Display = "block "? "../Images/openfold.gif": "../images/closedfold.gif ";
IMG. Alt = div. style. Display = "block "? "Close": "Expand ";
}
// -->
</SCRIPT>
</Head>
<Body class = "body1">
<Table>
<Tr>
<TD valign = "TOP" nowrap = "nowrap">
<% = Clientmanager. getinstance (). getclienttreehtmlstring () %>
</TD>
</Tr>
</Table>
</Body>
</Html>