新手跟着视频学的,运行后什么也不显示
index.jsp
<%!
private void tree(List<Article> articles,Connection conn,int id,int grade){
String sql = "select*from article where pid = "+ id;
Statement stmt = DB.getStmt(conn);
ResultSet rs = DB.executeQuery(stmt,sql);
try{
while(rs.next()){
Article a = new Article();
a.setId(rs.getInt("id"));
a.setPid(rs.getInt("pid"));
a.setRootId(rs.getInt("rootid"));
a.setTitle(rs.getString("title"));
a.setLeaf(rs.getInt("isLeaf") == 0?true : false);
a.setPdate(rs.getDate("pdate"));
a.setGrade(grade);
articles.add(a);
if(!a.isLeaf()){
tree(articles,conn,a.getId(),grade + 1);
}
} }catch(SQLException e){
e.printStackTrace();
}
}
%>
<%
List<Article> articles = new ArrayList<Article>();
Connection conn = DB.getConn();
tree(articles,conn,0,0);
DB.close(conn);
%> <body>
<% for(Iterator<Article> it = articles.iterator(); it.hasNext(); ) {
Article a = it.next();
%>
<tr>This is my JSP page.</tr>
<%
} %>
Article.java
index.jsp
<%!
private void tree(List<Article> articles,Connection conn,int id,int grade){
String sql = "select*from article where pid = "+ id;
Statement stmt = DB.getStmt(conn);
ResultSet rs = DB.executeQuery(stmt,sql);
try{
while(rs.next()){
Article a = new Article();
a.setId(rs.getInt("id"));
a.setPid(rs.getInt("pid"));
a.setRootId(rs.getInt("rootid"));
a.setTitle(rs.getString("title"));
a.setLeaf(rs.getInt("isLeaf") == 0?true : false);
a.setPdate(rs.getDate("pdate"));
a.setGrade(grade);
articles.add(a);
if(!a.isLeaf()){
tree(articles,conn,a.getId(),grade + 1);
}
} }catch(SQLException e){
e.printStackTrace();
}
}
%>
<%
List<Article> articles = new ArrayList<Article>();
Connection conn = DB.getConn();
tree(articles,conn,0,0);
DB.close(conn);
%> <body>
<% for(Iterator<Article> it = articles.iterator(); it.hasNext(); ) {
Article a = it.next();
%>
<tr>This is my JSP page.</tr>
<%
} %>
Article.java
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货