JSP中如何实现树型结构的显示?

qffhq 2003-09-07 12:56:23
我帮朋友看了一个JSP 做的网页,其中树型结构的显示出现了问题,查了一下是JSP做的
在文件xtree.js中的过程如下:


Sub CreateNote()
{
.......
tmp=new string(GetChildTree(0,0);
if.....
.......
}

'相关的子过程GetChildTree如下:

function GetChildTree()
{
var xmlhttp=new ActiveObject("Micro.XMLHTTP");
xmlhttp.open ("get","xtree.asp?partID=0...",false);
xmlhttp.send();
return bytes2BSTR(xmlhttp.responseBody);
}


在运行时,在retrun...这一句中出现,对象无效xmlhttp.responseBody,

由于我以前没用过Java,也没做过WEB方式的程序,所以不知道如何调试,
我想是xmlhttp.responseBody属性无效吧!
急急急?


...全文
310 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenfei00 2003-09-13
  • 打赏
  • 举报
回复
<%
<!-- 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>
<%
}
//sql_s.close();
//rs.close
//sql_s="";
//rs="";
%>
</table>
</DIV>
<%
}
%>
</body>
</html>
超级大笨狼 2003-09-13
  • 打赏
  • 举报
回复
仿照csdn左面的菜单的ASP+数据库无限级树菜单代码分享

近来问无限级数据库树菜单人很多,我就自己做了一个仿照csdn左面的菜单,自己暂时不用,完全是给大家分享的,要数据库和代码文件请到www.ymdg.com/tree.rar下载,如果有人提供空间存放那是最好了。
本文完全采用大家熟悉的ASP(VBS)制作,过写日子我再写一个基于XML技术的给大家。
QQ:28963147,email:panyuguang962@sohu.com
感谢CSDN和全体网友!
说明:
Access数据库
● 数据库名:tree
● 表名:tree
● 字段名的设计
ID 文本类型 编码
Name 文本类型 节点文字
HyperLink 文本类型 相关信息
---------------------------------------------------
ID | Name | HyperLink
---------------------------------------------------
1_1_1 | ASP | http://www.csdn.net
---------------------------------------------------
1_1_1_1 | DHTML | http://www.csdn.net
---------------------------------------------------
1_2_2 | JAVA | http://www.csdn.net
---------------------------------------------------
1_1_2 | JavaScript | http://www.csdn.net
---------------------------------------------------
1_2_1 | VB | http://www.csdn.net
---------------------------------------------------
1_2_1_2 | VBA | http://www.csdn.net
---------------------------------------------------
1_1 | WEB开发 | http://www.csdn.net
---------------------------------------------------
1 | WWW.CSDN.net | http://www.csdn.net
---------------------------------------------------
1_2_1_1 | 基础类 | http://www.csdn.net
---------------------------------------------------
1_3_1 | 基础类 | http://www.csdn.net
---------------------------------------------------
1_2 | 开发语言 | http://www.csdn.net
---------------------------------------------------
1_1_1_2 | 内建对象 | http://www.csdn.net
---------------------------------------------------
1_3 | 数据库 | http://www.csdn.net
----------------------------------------------------
文件:nolimited.asp经简单测试好用!代码如下:
<html>
<head>
<META name=VI60_defaultClientScript content=VBScript>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>asp树的研究</title>
</head>
<style type="text/css">
<!--
.aa {
font-size: 14px;
color: #000000;
text-align: center;
vertical-align: middle;
letter-spacing: 0px;
word-spacing: 0px;
}
-->
</style>
<body bgcolor="DEE3F7">
<%
dim cn,rs,SQL ,Para,NumChild
set cn=server.CreateObject("ADODB.connection")
set rs=server.createobject("ADODB.recordset")
set rs1=server.createobject("ADODB.recordset")
cn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("tree.mdb")
SQL="Select * from tree order by ID"
rs.open SQL,cn,3,2
do while not rs.EOF
SQL="Select ID from tree where ID like '" & rs("ID") & "%' and ID<>'" & rs("ID") & "' order by ID"
Para=rs("ID") & "|"
NumChild=0
rs1.open SQL,cn, 3,2
NumChild=rs1.RecordCount
do while not rs1.EOF
Para =Para & rs1("ID") & "|"
rs1.MoveNext
loop
Para=cstr(trim(left(Para,len(Para)-1)))
rs1.Close
%>
<table id="T<%=rs("ID")%>"
border=1
cellpadding=0
cellspacing=0
bordercolor="#DEE3F7"
class="aa"
abbr="<%=Para%>"
summary=<%=checkid(rs("ID"))%>
style="cursor:hand"
onClick="vbs:subtree '<%=Para%>'" >

<tr>
<td width="<%=17+checkid(rs("ID"))*20%>"
height="20" align="right">
<table width="20" height="20" border="1" cellpadding="0" cellspacing="0" bordercolor="#DEE3F7">
<tr>

<td align="center" valign="middle" bordercolor="#000000" id="R<%=rs("ID")%>" ><%if NumChild=0 then Response.Write "." else Response.Write "-"%></td>
</tr>
</table>
</td>

<td height="20"
nowrap
bordercolor="#FFFFFF"
onMouseOver="vbs:me.bgcolor='#CCCCCC':me.bordercolor='#999999'"
onMouseOut="vbs:me.bgcolor='#DEE3F7':me.bordercolor='#ffffff'"
title="<%=rs("HyperLink")%>">
<%=rs("Name")%></td>
</tr>
</table>


<%
rs.MoveNext
loop
rs.Close:set rs=nothing
cn.Close:set cn=nothing
function checkid(x)
dim Tempnum
Tempnum=0
for i=1 to len(x)
if mid(x,i,1)="_" then
Tempnum=Tempnum+1
end if
next
checkid=Tempnum
end function


%>
<script language=VBS>
sub subtree(Client_para)
if instr(Client_para,"|")=0 then exit sub
Myarray=split(Client_para,"|")
Mytext=eval("R" & Myarray(0) & ".innertext")
select case Mytext
case "+"
document.all.item("R" & Myarray(0)).innertext="-"
for i=1 to ubound(Myarray)
if eval("T" & Myarray(i) & ".summary")-eval("T" & Myarray(0) & ".summary")=1 then
document.all.item("T" & Myarray(i)).style.display="block"
end if
if eval("T" & Myarray(i) & ".summary")-eval("T" & Myarray(0) & ".summary")>1 then
document.all.item("T" & Myarray(i)).style.display="none"
end if
next
case "-"
document.all.item("R" & Myarray(0)).innertext="+"
for i=1 to ubound(Myarray)
if eval("T" & Myarray(i) & ".summary")-eval("T" & Myarray(0) & ".summary")>=1 then
document.all.item("T" & Myarray(i)).style.display="none"
if eval("R" & Myarray(i) & ".innertext")="-" then
document.all.item("R" & Myarray(i)).innertext="+"
end if
end if
next
end select
set Myarray=nothing
end sub

Sub document_onselectstart
document.selection.clear
End Sub

if isobject(eval("T1")) then
subtree document.all("T1").abbr
subtree document.all("T1").abbr
end if
</script>

</html>




yim 2003-09-08
  • 打赏
  • 举报
回复
js不知识是什么,是不是javascrip?
听你们这一说JSP不能写树那,那XML呢?

to:junnef(光明圣堂武士)
你只需要用jsp来打印生成js.....用js可以让树产生动作,如果纯jsp,只能得到棵死树,画 table和图片直接用jsp打印。
能不能说具体点,我还没入门呢!

to:dwju1981
能不能拿出那分享下!!!

我是菜鸟,我怕谁!


dwju1981 2003-09-08
  • 打赏
  • 举报
回复
JSP做树好象有点问题,最好用脚本,我有一个不限层不限接点的树,嘿嘿……
junnef 2003-09-08
  • 打赏
  • 举报
回复
你只需要用jsp来打印生成js,想用jsp直接来做树,没见过,树是运行在客户端给用户看的,服务器端只能生成,用js可以让树产生动作,如果纯jsp,只能得到棵死树,画table和图片直接用jsp打印。
kaibinsj 2003-09-08
  • 打赏
  • 举报
回复
这个是用js做的,跟jsp没什么关系,纯粹用jsp来实现的,我也想看看。
听说.net实现树型很容易,所有也关注jsp的实现。
yim 2003-09-08
  • 打赏
  • 举报
回复
谢谢楼上的,我正要做个树形图,可我JSP还没入门,不知道从何下手.
各位前辈给出的"秘籍".俺想回去好好练.可不知前辈们能不能说下用JSP写个树形图大概思想.我想做树形图应该要和数据库连起来,从数据库读出数据再构建树形图.
请前辈们指教!
yimage 2003-09-07
  • 打赏
  • 举报
回复
给你个例子
<script language="JavaScript">
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;



if (ver4) {
with (document) {
write("<STYLE TYPE="text/css">");
if (NS4) {
write(".parent {position:absolute; visibility:visible}");
write(".child {position:absolute; visibility:visible}");
write(".regular {position:absolute; visibility:visible}")
}
else {
write(".child {display:none}")
}
write("</STYLE>");
}
}



function getIndex(el) {
ind = null;
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id == el) {
ind = i;
break;
}
}
return ind;
}



function arrange() {
nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
for (i=firstInd+1; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.visibility != "hide") {
whichEl.pageY = nextY;
nextY += whichEl.document.height;
}
}
}



function initIt(){
if (!ver4) return;
if (NS4) {
for (i=0; i<document.layers.length; i++) {
whichEl = document.layers[i];
if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
}
arrange();
}
else {
divColl = document.all.tags("DIV");
for (i=0; i<divColl.length; i++) {
whichEl = divColl(i);
if (whichEl.className == "child") whichEl.style.display = "none";
}
}
}



function expandIt(el) {
if (!ver4) return;
if (IE4) {
whichEl = eval(el + "Child");
if (whichEl.style.display == "none") {
whichEl.style.display = "block";
}
else {
whichEl.style.display = "none";
}
}
else {
whichEl = eval("document." + el + "Child");
if (whichEl.visibility == "hide") {
whichEl.visibility = "show";
}
else {
whichEl.visibility = "hide";
}
arrange();
}
}
onload = initIt;
</script>
</font></p>
<div id="KB1Parent" class="parent">    <a href="#" onClick="expandIt("KB1"); return false" ><img src="img/plus.gif" border=0>文件夹一</a></div>
<div id="KB1Child" class="child">     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面一</a><br>
     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面二</a><br>
     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面三</a></div>
<div id="KB2Parent" class="parent">    <a href="#" onClick="expandIt("KB2"); return false" ><img src="img/plus.gif" border=0>文件夹二</a></div>
<div id="KB2Child" class="child">     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面一</a><br>
     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面二</a><br>
     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt="" width="15" height="11"><img src="img/open.gif" border=0>页面三</a></div>
<div id="KB3Parent" class="parent">    <a href="#" onClick="expandIt("KB3"); return false" ><img src="img/plus.gif" border=0>文件夹三</a></div>
<div id="KB3Child" class="child">      <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面一</a><br>
      <a href="sample.htm" target="_blank" ><img src="img/open.gif" border=0>页面二</a><br>
     <a href="sample.htm" target="_blank" ><img src="img/spacer.gif" border=0 alt=""><img src="img/open.gif" border=0>页面三</a></div>
<script language="JavaScript">
if (NS4) {
firstEl = "KB1Parent";
firstInd = getIndex(firstEl);
arrange();
}
</script>
dmhorse 2003-09-07
  • 打赏
  • 举报
回复
Use dtree

the tree using javascript is simpler than jsp.

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧