Servlet内容:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session=request.getSession();
ArticleDao articleDao = new ArticleDao();
List articleList = null;
try {
articleList = articleDao.queryArticle(1, null);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("articleList",articleList);
RequestDispatcher rd=request.getRequestDispatcher("blog.jsp");
rd.forward(request, response);
}
public List queryArticle(int art_id,String art_title) throws SQLException{
List articlelist = (List) new ArrayList();
String sql="";
Connection connection = DBconnect.getConnection();
PreparedStatement pstmt = connection.prepareStatement(sql);
sql="select top 3 * from article order by art_time desc";
ResultSet rs = pstmt.executeQuery();
if(rs!=null){
try {
while(rs.next()){
articleBean.setArt_id(rs.getInt(1));
articleBean.setArt_title(rs.getString(2));
articleBean.setArt_type(rs.getString(3));
articleBean.setArt_time(rs.getString(4));
articleBean.setArt_content(rs.getString(5));
articleBean.setPl_count(rs.getInt(6));
articleBean.setVote_count(rs.getInt(7));
/*sql="select comment_id from comment where art_id="+articleBean.getArt_id();
ResultSet rsr=pstmt.executeQuery();
if(rsr!=null){
rsr.next();
articleBean.setPl_count(rsr.getInt(1));
rsr.close();
}
((ArrayList) articlelist).add(articleBean);*/
}
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
}
}
return articlelist;
}
}
在博客首页进行部分文章显示时,单步调试显示articleSingle为null.是怎么一回事呢
看了更新。
queryArticle
方法实现上你的list
的add
都被注释了,就算你怎么查到数据,list一直都是初始状态,没有数据