项目中需要显示部门信息,请问在JSP页面中如何显示呢?JSP

解决方案 »

  1.   

    服务器端获取数据后由js去构建树形结构,网上很多js实现的树可以用。
      

  2.   

    也就是tree的问题咯动态的,你看怎么样?
      

  3.   

    Struts2动态树型从数据库取出 
    后台数据层代码:public TEquipmentTree[] getChildren(String treeNodeId) throws Exception {
      Connection conn = getConnection();
      PreparedStatement smt = conn.prepareStatement("select * from t_equipmentclass where eql_pcode ='"+treeNodeId+"'");
      
      ResultSet rs = smt.executeQuery();
      List<TEquipmentTree> childList = new ArrayList<TEquipmentTree>();
      while (rs.next()) {
       TEquipmentTree TEquipmentTree = new TEquipmentTree();
       TEquipmentTree.setEqlCode(rs.getString("eql_code"));
       TEquipmentTree.setEqlName(rs.getString("eql_name"));
       TEquipmentTree.setEqlPcode(rs.getString("eql_pcode"));
       TEquipmentTree.setEqlLevel(rs.getInt("eql_level"));
       TEquipmentTree.setEqlRe(rs.getString("eql_re"));
       TEquipmentTree.setChildEquipment(getChildren(TEquipmentTree.getEqlCode()));
       childList.add(TEquipmentTree);
      }
      rs.close();
      smt.close();
      conn.close();
      TEquipmentTree[] childResult = new TEquipmentTree[childList.size()];
      childResult = childList.toArray(childResult);
      return childResult;
     }public TEquipmentTree[] getAllTEquipmentTree() throws Exception {
      String sql="select * from T_Equipmentclass where EQL_PCODE='EEW1001'";
      Connection conn = getConnection();
      PreparedStatement smt = conn.prepareStatement(sql);
      ResultSet rs = smt.executeQuery();
      List<TEquipmentTree> TEquipmentTreeList = new ArrayList<TEquipmentTree>();
      while (rs.next()) {
       TEquipmentTree TEquipmentTree = new TEquipmentTree();
       TEquipmentTree.setEqlCode(rs.getString("EQL_CODE"));
       TEquipmentTree.setEqlName(rs.getString("EQL_NAME"));
       TEquipmentTree.setEqlPcode(rs.getString("EQL_PCODE"));
       TEquipmentTree.setEqlLevel(rs.getInt("EQL_LEVEL"));
       TEquipmentTree.setEqlRe(rs.getString("EQL_REMARK"));
       TEquipmentTree.setChildEquipment(getChildren(TEquipmentTree.getEqlCode()));
       TEquipmentTreeList.add(TEquipmentTree);  }
      rs.close();
      smt.close();
      conn.close();
      TEquipmentTree[] TEquipmentTree = new TEquipmentTree[TEquipmentTreeList.size()];
      TEquipmentTree = TEquipmentTreeList.toArray(TEquipmentTree);
      return TEquipmentTree;
     }前台页面:<s:head theme="ajax"/>
    <script type="text/javascript">
    function treeNodeSelected(arg) {
     window.returnValue=arg.source.title+","+arg.source.widgetId;
     window.close();
     //arg.source.widgetId+","
     //window.opener.document.getElementById("eqlCode").value=arg.source.widgetId;
     //alert(arg.source.title);
     //window.opener.document.getElementByName("eqlName").value=arg.source.title;
     //alert("id["+arg.source.widgetId+"], name["+ arg.source.title+ "] selected");
       }
       dojo.addOnLoad(function() {                
          var s = dojo.widget.byId('tree').selector;                
          dojo.event.connect(s, 'select', 'treeNodeSelected');
       });
    </script>
    </head>
    <body>
    <s:form>
     <s:tree id="tree" 
     rootNode="root"
     nodeIdProperty="eqlCode" 
     nodeTitleProperty="eqlName" 
     childCollectionProperty="childEquipment" 
     treeSelectedTopic="treeSelected" 
     theme="ajax" 
     showRootGrid="false">
     </s:tree>
    </s:form>
      

  4.   

    在后台写tree结构,或者用ztree、dtree都可以。不建议用js写