如何在JSP中显示树形结构的数据 项目中需要显示部门信息,请问在JSP页面中如何显示呢?JSP 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 服务器端获取数据后由js去构建树形结构,网上很多js实现的树可以用。 也就是tree的问题咯动态的,你看怎么样? 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> 在后台写tree结构,或者用ztree、dtree都可以。不建议用js写 ssh2中自定义监听器的配置,求高手指点 java中file控件实现多选 初学JSP,这是什么错误?怎么解决呢 关于hibernate 更新数据的问题 访问oracle速度比较 使用DWR出现fail to find parameter:c0-scriptName问题 有人碰到过么 谁有修改后的增加toUtf8String方法jspSmartUpload.jar jetty服务器突然停止 探讨树型结构!!!!!!! 如何防止一个ID在不同的机器上同进登录? 提交表单后,获取不到图片路径? sql 语句的写法
后台数据层代码: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>