Div tree menu

Source: Internet
Author: User

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>

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.