http://expert.csdn.net/Expert/topic/1510/1510939.xml?temp=.5489771

解决方案 »

  1.   

    <%
    <!-- conn.jsp -->
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=tree";
    //Database后面值为你的数据库名
    String user="sa";//用户
    String password="";//密码
    Connection conn= DriverManager.getConnection(url,user,password);
    Statement smt=conn.createStatement(),smt_1=conn.createStatement(),smt_2=conn.createStatement();
    //Statement 
    String sql;
    %><!-- tree.jsp -->
    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.lang.*"%>
    <%@include file="conn.jsp"%>
    <html>
    <head>
    <link href="inc/style.css" rel="stylesheet">
    <title>树型目录</title>
    </head>
    <script language="JavaScript">
    <!--
    function mover(where){
    where.style.cursor='hand';
    }
    function mout(where){
    //where.style.cursor='hand';
    }
    function view(obj,pic)
    {
    if (document.all[obj].style.display=="")
    {
    document.all[obj].style.display="none";
    //alert("合并");
    pic.all.tags('img')[0].src="images/icon-folder1-close.gif";
    pic.all.tags('img')[1].src="images/icon_close.gif";
    }
    else 
    {
    document.all[obj].style.display="";
    //alert("打开");
    pic.all.tags('img')[0].src="images/icon-folder1-open.gif";
    pic.all.tags('img')[1].src="images/icon_open.gif";
    }
    }
    //-->
    </script>
    <body>
    <%
    String str1;
    sql="select * from f_item";
    ResultSet F_rs=smt_1.executeQuery(sql);
    while(F_rs.next())
    {
    str1=F_rs.getString("F_Name");
    //out.print(str1);
    %>
      <table OnMouseOver="mover(this)" OnMouseOut="mout(this)" OnClick="view('Label<%=F_rs.getString("id")%>',this)" height="16" border="0" cellpadding="0" cellspacing="1">
        <tr>
          <td><img src="images/icon-folder1-close.gif" width="15" height="13"><img src="images/icon_close.gif" width="16" height="16"><%=F_rs.getString("F_Name")%></td>
    </tr>
    </table>
    <DIV id=Label<%=F_rs.getString("id")%> style="display:none">
      <table width="200" height="16" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
        <%
    sql="select * from s_item where f_name='"+str1+"'";
    ResultSet rs_s=smt_2.executeQuery(sql);
    while(rs_s.next())
    {
    %>
        <tr> 
          <td width="50" valign="top"><font color="#FF0000"><img src="images/blank.gif" width="50" height="16"></font></td>
          <td height="16"><font color="#FF0000"><%=rs_s.getString("S_Name")%></font></td>
        </tr>
        <%
    }
        %>
      </table>
    </DIV>
    <%
    }
    %>
    </body>
    </html>