Iterator迭代什么也不显示

qq_41073896 2017-12-09 07:42:20
新手跟着视频学的,运行后什么也不显示
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
...全文
415 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
更好的自己520 2017-12-30
  • 打赏
  • 举报
回复
你的迭代代码应该没什么问题啊,是不是你获取到的article对象中本来就没值,为空导致的?
oyljerry 2017-12-29
  • 打赏
  • 举报
回复
先看有没有拿到正确的内容,然后在iterator
Mr_NEMO 2017-12-29
  • 打赏
  • 举报
回复
在循环里你没有输出你的Article对象信息到页面
什么都不能 2017-12-10
  • 打赏
  • 举报
回复
我觉得你可以换一个视频,从jsp开始学没问题,但学的时候就要按照规矩来,不规矩的代码不能学。
Defonds 2017-12-10
  • 打赏
  • 举报
回复
你先确认一下你得到的 articles 是否有内容
xiaovhao 2017-12-10
  • 打赏
  • 举报
回复
sql报错了吧,String sql = "select*from article where pid = "+ id; 中间应该要有空格 String sql = "select * from article where pid = "+ id;

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧