这样吧,可否不使用递归也可以实现以上目录树的结构!!!我的代码是
<%!
String sId;
String sName;
String sTemp;
ResultSet rset=null;
int iCount=0;
int iLen = 0;
int iLength = 3;
int iLens=3;
%>
<div>
<span><input type=checkbox>企业</span>
<UL id=root>
<%
rset=conn.executequery("select * from tree order by id");
//主目录信息
while (rset.next())
{
sId = rset.getString("id");
iLen = sId.length();
sName=rset.getString("name");
ResultSet rs = conn.executequery("select count(*) as icount from tree where id like: '"+sId+"%'");
if(rs.next()) iCount = rs.getInt("icount");//得到是否有下级目录
if(iCount==1)
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<%
}
if((iCount>1)&&((iLength-iLen==0)||(iLen % iLength==0)))
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<UL>
<%
}
if(iLen-iLens<0)
{
%>
</UL><%
} iLens = iLen;
}
%>
</UL>
</div>
但是在没有子目录情况下就会出错!!如何更改?或者有更好的解决办法
<%!
String sId;
String sName;
String sTemp;
ResultSet rset=null;
int iCount=0;
int iLen = 0;
int iLength = 3;
int iLens=3;
%>
<div>
<span><input type=checkbox>企业</span>
<UL id=root>
<%
rset=conn.executequery("select * from tree order by id");
//主目录信息
while (rset.next())
{
sId = rset.getString("id");
iLen = sId.length();
sName=rset.getString("name");
ResultSet rs = conn.executequery("select count(*) as icount from tree where id like: '"+sId+"%'");
if(rs.next()) iCount = rs.getInt("icount");//得到是否有下级目录
if(iCount==1)
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<%
}
if((iCount>1)&&((iLength-iLen==0)||(iLen % iLength==0)))
{
%>
<LI><span><input type=checkbox value=<%=sId%>> <%=sName%></span>
<UL>
<%
}
if(iLen-iLens<0)
{
%>
</UL><%
} iLens = iLen;
}
%>
</UL>
</div>
但是在没有子目录情况下就会出错!!如何更改?或者有更好的解决办法
把
int iCount=0;
放到下面的位置
ResultSet rs = conn.executequery("select count(*) as icount from tree where id like: '"+sId+"%'");
int iCount=0;
if(rs.next()) iCount = rs.getInt("icount");//得到是否有下级目录
同时,请真正认识kw123的作风:说到做到;只要你行!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!