JSP实现个人博客

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.是怎么一回事呢
请输入图片描述

阅读 5.8k
1 个回答

看了更新。
queryArticle方法实现上你的listadd都被注释了,就算你怎么查到数据,list一直都是初始状态,没有数据

推荐问题
logo
101 新手上路
子站问答
访问
宣传栏