如何在JSP中显示树形结构的数据
项目中需要显示部门信息,请问在JSP页面中如何显示呢?
JSP
------解决方案--------------------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.setEqlRemark(rs.getString("eql_remark"));
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.setEqlRemark(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("eqlNa