怎么我的这个JSP树形目录程序出错

mdot 2003-02-14 11:04:41
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="workM" scope="page" class="test.faq"/>
<html>
<head>
<title>无限级菜单测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<script language="javascript">
function expands(expid,picid) //显示图片张合的Js
{ // alert("this.document.all["+expid+"].style.display");
if(this.document.all[expid].style.display=="none")
{ this.document.all[expid].style.display="block";
this.document.all[picid].src="line_01_02.gif";

}
else
{
this.document.all[expid].style.display="none";
this.document.all[picid].src="line_01.gif";
}
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<%
try {
ResultSet rs=workM.executeQuery("select * from board1 where parentid=0");
int id=rs.getInt("id");
String boardname=rs.getString("boardname");
}
catch (SQLException e)
{
}


%>
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" width="766" bordercolor="#DDCF90" height="392">
<tr>
<td valign="top">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="372">
<tr>
<td width="368"><a onclick="javascript:expands('dwtop','dwimg')" style="cursor:hand"><span align="absmiddle"> <img id="dwimg" SRC="line_01.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2"><a href="tree.jsp?parentid=<%=id%>"><%=boardname%></a></font>
<table id="dwtop" style="display=none" cellspacing="0" cellpadding="0">
<%
ListChildTree(0,0);
%>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</center>
</div>

</body>
</html>


<%!
public void ListChildTree(int parentid,int level){
try {
ResultSet rs=workM.executeQuery("select * from board1 where parentid=0");
String sql="";
while (rs.next())
{
int id=rs.getInt("id");
String boardname=rs.getString("boardname");
int level=rs.getInt("level");
String space="";
for (int j=0;j<level;j++)
Space+=" "; //设置显示节点前面的距离,这里的空格的html被这里自动替换成" "了

int childcount=0;
sql ="select count(*) as childcount from board1 where parentid="+id;//查找孩子节点的孩子节点
try {
ResultSet rs1=workM.executeQuery(sql);
if (rs1.next())
{
childcount=rs1.getInt("childcount");
}
rs1.close();
}
catch (SQLException e){
}
int TableId=childcount; //设置表格Id
int TablePic=childcount; //设置图片Id
if (childcount=0)
{
%>
<tr><td><%=Space%><span align="absmiddle"><img src="line_01_02.gif" border="0" align="absmiddle" width="35" height="17"></span><font size="2"><A href="process.php"><%=rs.getString("boardname")%></a></font>
<table id="<%=TableId%>" style="display=none" cellspacing="0" cellpadding="0">

<%
}
else
{
%>
<tr><td><%=Space%><a onclick="javascript:expands('<%=$TableId%>','<%=$TablePic%>')" style="cursor:hand"><span align="absmiddle"><img id="<%=$TablePic%>" src="line_01.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2"><%=boardname%></a></font>
<table id="<%=TableId%>" style="display=none" cellspacing="0" cellpadding="0">
<%
ListChildTree(id,level);//递归调用函数本身来显示其他孩子节点
}%>
</table>
<%


}
catch (SQLException e)
{
}
}
%>
其中WORKM为一个连接数据库的BEAN。该程序是用来动态从数据库
读取数据形成树形目录,但编译时出错
An error occurred between lines: 69 and 99 in the jsp file: /tree.jsp

Generated servlet error:
D:\jakarta-tomcat-4.0.3\work\localhost\hello1\tree$jsp.java:44: '}' expected.
{
^

D:\jakarta-tomcat-4.0.3\work\localhost\hello1\tree$jsp.java:48: Statement expected.
static {
^


An error occurred between lines: 103 and 107 in the jsp file: /tree.jsp

Generated servlet error:
D:\jakarta-tomcat-4.0.3\work\localhost\hello1\tree$jsp.java:196: 'try' without 'catch' or 'finally'.
else
^


An error occurred between lines: 103 and 107 in the jsp file: /tree.jsp

Generated servlet error:
D:\jakarta-tomcat-4.0.3\work\localhost\hello1\tree$jsp.java:196: 'else' without 'if'.
else
^


An error occurred between lines: 114 and 122 in the jsp file: /tree.jsp

Generated servlet error:
D:\jakarta-tomcat-4.0.3\work\localhost\hello1\tree$jsp.java:260: Type expected.
catch (SQLException e)
^
5 errors
但我看过,好象没错呀?
...全文
66 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 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>




mdot 2003-02-14
  • 打赏
  • 举报
回复
还是同样的错误呀!
数据库的结构是
id parentid boardname level
1 0 abc 1
2 1 dfdf 2
3 2 dfd 3

level表示树的层数
study_body 2003-02-14
  • 打赏
  • 举报
回复
<body bgcolor="#FFFFFF" text="#000000">
<%
try {
ResultSet rs=workM.executeQuery("select * from board1 where parentid=0");
int id=rs.getInt("id");
String boardname=rs.getString("boardname");
}
catch (SQLException e) { }


%>
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" width="766" bordercolor="#DDCF90" height="392">
<tr>
<td valign="top">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="372">
<tr>
<td width="368"><a onclick="javascript:expands('dwtop','dwimg')" style="cursor:hand"><span align="absmiddle"> <img id="dwimg" SRC="line_01.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2"><a href="tree.jsp?parentid=<%=id%>"><%=boardname%></a></font>
<table id="dwtop" style="display=none" cellspacing="0" cellpadding="0">
<%
ListChildTree(0,0);
%>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</center>
</div>

</body>
</html>


<%!
public void ListChildTree(int parentid,int level)
{
try {
ResultSet rs=workM.executeQuery("select * from board1 where parentid=0");
String sql="";
while (rs.next())
{
int id=rs.getInt("id");
String boardname=rs.getString("boardname");
int level=rs.getInt("level");
String space="";
for (int j=0;j<level;j++) Space+=" "; //设置显示节点前面的距离,这里的空格的html被这里自动替换成" "了
int childcount=0;
sql ="select count(*) as childcount from board1 where parentid="+id;//查找孩子节点的孩子节点
try
{
ResultSet rs1=workM.executeQuery(sql);
if (rs1.next())
{
childcount=rs1.getInt("childcount");
}
rs1.close();
}
catch (SQLException e)
{
}
int TableId=childcount; //设置表格Id
int TablePic=childcount; //设置图片Id
if (childcount=0)
{
%>
<tr><td><%=Space%><span align="absmiddle"><img src="line_01_02.gif" border="0" align="absmiddle" width="35" height="17"></span><font size="2"><A href="process.php"><%=rs.getString("boardname")%></a></font>
<table id="<%=TableId%>" style="display=none" cellspacing="0" cellpadding="0">

<%
}
else
{
%>
<tr><td><%=Space%><a onclick="javascript:expands('<%=$TableId%>','<%=$TablePic%>')" style="cursor:hand"><span align="absmiddle"><img id="<%=$TablePic%>" src="line_01.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2"><%=boardname%></a></font>
<table id="<%=TableId%>" style="display=none" cellspacing="0" cellpadding="0">
<%
ListChildTree(id,level);//递归调用函数本身来显示其他孩子节点
}
%>
</table>
<%
}
}
catch (SQLException e)
{
}
}
%>

注意编码格式
mdot 2003-02-14
  • 打赏
  • 举报
回复
现在修改了该程序,但一直是死循环,想各位大侠指教下如何修改?
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="workM" scope="page" class="test.faq"/>
<html>
<head>
<title>无限级菜单测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javascript">
function expands(expid,picid) //显示图片张合的Js
{ // alert("this.document.all["+expid+"].style.display");
if(this.document.all[expid].style.display=="none")
{ this.document.all[expid].style.display="block";
this.document.all[picid].src="line_01_02.gif";

}
else
{
this.document.all[expid].style.display="none";
this.document.all[picid].src="line_01.gif";
}
}
</script>


<body bgcolor="#FFFFFF" text="#000000">
<%
try {
ResultSet rs=workM.executeQuery("select * from board1 where parentid=0");
int id=rs.getInt("id");
String boardname=rs.getString("boardname");
}
catch (SQLException e) { }


%>
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" width="766" bordercolor="#DDCF90" height="392">
<tr>
<td valign="top">
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="372">
<tr>
<td width="368"><a onclick="javascript:expands('dwtop','dwimg')" style="cursor:hand"><span align="absmiddle"> <img id="dwimg" SRC="line_01.gif" border="0" align="absmiddle" width="35" height="17"></span></a><font size="2">
<!--a href="tree.jsp"--><%//=boardname%></a></font>
<table id="dwtop" style="display=none" cellspacing="0" cellpadding="0">
<% out.println(workM.ListChildTree(0,0));%>
</table>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</center>
</div>

</body>
</html>


其中workM.ListChildTree的LISTCHILDTREE方法为
public String ListChildTree(int parentid,int level)
{
rs=null;
//String list="";
try {
conn = DriverManager.getConnection(sConnStr,"sa","");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);


rs=stmt.executeQuery("select * from board1 where parentid=0");
String sql="";

while (rs.next())
{
int id=rs.getInt("id");
String boardname=rs.getString("boardname");
int level1=rs.getInt("level");
String space="";
for (int j=0;j<level1;j++) space+=" "; //设置显示节点前面的距离,这里的空格的html被这里自动替换成" "了
int childcount=0;
sql ="select count(*) as childcount from board1 where parentid="+id;//查找孩子节点的孩子节点
try
{
rs1=stmt.executeQuery(sql);
if (rs1.next())
{
childcount=rs1.getInt("childcount");
}
rs1.close();
}
catch (SQLException e)
{
}
int TableId=childcount; //设置表格Id
int TablePic=childcount; //设置图片Id
if (childcount==0)
{
list+="<tr><td>h<span align='absmiddle'><img src='line_01_02.gif' border='0' align='absmiddle' width='35' height='17'></span><font size='2'><A href='process.php'>"+boardname+"</a></font><table id='"+TableId+"' style='display=none' cellspacing='0' cellpadding='0'>";

}
else
{
list+="<tr><td>h<a onclick='javascript:expands('"+TableId+"','"+TablePic+"')' style='cursor:hand'><span align='absmiddle'><img id='"+TablePic+"' src='line_01.gif' border='0' align='absmiddle' width='35' height='17'></span></a><font size='2'>"+boardname+"</a></font><table id='"+TableId+"' style='display=none' cellspacing='0' cellpadding='0'>";

list+=ListChildTree(id,level);//递归调用函数本身来显示其他孩子节点
}

list+="</table></td></tr>";

}
}
catch (SQLException e)
{
}
return list;
}

81,114

社区成员

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

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