动态菜单加载失败,,
TreeDao.java:
package com.lym.struts.business;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.lym.struts.model.DBConnection;
public class TreeDao {
private Connection conn = null;
private PreparedStatement ps = null;
private DBConnection dbconn = null;
public TreeDao() {
dbconn = new DBConnection();
conn = dbconn.getDBConnection();
}
public List<TreeBean> allTree() {
List<TreeBean> list = new ArrayList<TreeBean>();
TreeBean bean = null;
String sql = "select id, pid, name from tree";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()){
bean = new TreeBean();
bean.setId(rs.getString("id"));//节点编号
bean.setPid(rs.getString("pid"));//父节点编号
bean.setName(rs.getString("name")); //节点名称
//bean.setUrl(rs.getString("url"));//链接地址
list.add(bean);
}
}
catch (SQLException ex){
}
return list;
}
}
tree.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<jsp:useBean id="treeDao" scope="page" class="com.lym.struts.business.TreeDao" />
<%
List<?> list = treeDao.allTree();
session.setAttribute("treeList", list);
//out.println(list);
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'tree.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link href="css/text.css" rel="stylesheet" type="text/css" />
<link href="css/dtree.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/dtree.js"></script>
</head>
<body>
<table>
<tr>
<td height="300" valign="top" nowrap>
<p><a href="javascript: tree.openAll();">open all</a> | <a href="javascript: tree.closeAll();">close all</a></p>
<script type="text/javascript">
tree = new dTree('tree');
<logic:iterate id="fun" name="treeList">
tree.add(
" <bean:write name="fun" property="id"/> ",
" <bean:write name="fun" property="pid"/> ",
" <bean:write name="fun" property="name"/>",
);
</logic:iterate>
document.write(tree);
</script>
</td>
</tr>
</table>
</body>
</html>
最终结果只显示:
open all| close all
别的都没有,也不报错,有大神能帮忙没?
[解决办法]
可以参考下面这个代码http://download.csdn.net/detail/u012591711/6462103