树型菜单的实现

该博客展示了一个JSP文件实现树型菜单的代码。包含页面样式设置、JavaScript函数控制菜单显示隐藏,还进行了用户权限验证,若角色ID或员工ID为空则提示重新登录。同时使用SQL查询数据库获取子区域信息用于菜单展示。

<!---
@FileName:tree3.jsp
@Author:曾斌
@Description:树型菜单
@Date:2005-2-23
--->
<%@ include file="../comm/relogin_frame.jsp"%>
<%@ include file="../comm/db.jsp"%>
<STYLE type=text/css>A:link {
 FONT-SIZE: 9pt; TEXT-DECORATION: none
}
A:active {
 FONT-SIZE: 9pt; TEXT-DECORATION: none
}
A:visited {
 FONT-SIZE: 9pt; TEXT-DECORATION: none
}
</STYLE>
<html>
<script  language=javascript> 
 function display1(num) { 
  if (document.all("subtree"+num).style.display=="none"){
            document.all("subtree"+num).style.display="";
   document.all("image"+num).src="../images/t_sub.gif";    
 }else {
         document.all("subtree"+num).style.display="none";
   document.all("image"+num).src="../images/t_plus.gif";
   
 }
}
</script> 

<%

   String roleid=(String)session.getAttribute("roleid");
   String staffid = (String)session.getAttribute("staffid");
   if(roleid==null||staffid==null) {
//if(true) {
     %>
     <script>
      alert("你超过60分钟没有访问该页面,请重新登录!");
      top.location="../index.jsp";
     </script>

     <% 
}
     if(roleid==null) roleid="000000";
     if(staffid==null) staffid="000000";
%>

<br>
<BODY style="FONT-SIZE: 9pt; FONT-FAMILY: 宋体; BACKGROUND-COLOR: #6699cc"  >

<%

 if(staffid==null) staffid="9999";
 if(roleid==null) roleid="DDD";
 String sql2 ="";
 Connection conn = ds.getConnection();
 PreparedStatement stmt =null;// conn.createStatement();
 ResultSet rs = null;
// String sql = "select * from t_sys_sub_area  order by subareaid";
String sql = "select a.* from t_sys_sub_area a, (select distinct subareaid     from dss_sys.V_SYS_STAFF_PRIV      where staffid = '"+staffid+"' ) b where a.subareaid = b.subareaid ";
//System.out.println(sql);
stmt = conn.prepareStatement(sql);
rs  = stmt.executeQuery();
 //rs = stmt.executeQuery(sql);
 int size = rs.getFetchSize();
 int i = 0;

 while(rs.next()) {
          int key = i + 1;
    i++;
          String Content = "zhugan" + key;
          String Aux = "subtree" + key;
          String item = "image" + key;
    String tt=""+key;
 %>

<SPAN id=<%=Content%> style="CURSOR: hand; COLOR: #ffffff;font: normal bold 8pt/9pt Times, serif;" onclick=display1(<%=key%>)>
<%if("subtree1".equals(Aux)){%>
<IMG src="../images/t_sub.gif" align=absMiddle name=<%=item%>><%=rs.getString("subareaname")%>
</SPAN>
<BR>


<DIV id=<%=Aux%> style="DISPLAY: ' '">
<%}else{%>
<IMG src="../images/t_plus.gif" align=absMiddle name=<%=item%>><%=rs.getString("subareaname")%>
</SPAN>
<BR>
<DIV id=<%=Aux%> style="DISPLAY: 'none'">
<%}%>
<%           

   ResultSet rs2 = null;   
   sql2=" select * from v_sys_staff_priv  where staffid='"+staffid+"' and subareaid='"+rs.getString("subareaid")+"'";
   //System.out.println(sql2);
   stmt = conn.prepareStatement(sql2);
   rs2  = stmt.executeQuery();
//   rs2 = stmt2.executeQuery(sql2);
   while (rs2.next())  {                                            
            %>
   <IMG src="../images/line_05.gif"align=absMiddle>
   <A
   href="right.jsp?subjectid=<%=rs2.getString("subjectid")%>"
   target=right>
   <FONT color=#ffffff><%=rs2.getString("subjectname")%></FONT>
   </A>
   <BR>
   <%
    }
   if(rs2!=null) rs2.close();
   //if(stmt2!=null) stmt2.close();
   
   %>

</DIV>
<%
}
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(conn!=null) conn.close();
%>
</body>
</html>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值