解决方案 »

  1.   

    很明显空指针错,第32行的list可能没取到值,是用的request.getAttribute()取的吗,或者把完整的jsp页面贴出来
      

  2.   

    <%@ page language="java" contentType="text/html; charset=UTF-8" %>
    <%@ page import="lvjianyu.blog.Blog" %>
    <%@ page import="lvjianyu.blog.Comment" %>
    <%@ page import="java.util.List" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>显示博文</title>
    </head><body>
    <% Blog blog=(Blog)request.getAttribute("blog");
    List list=(List)request.getAttribute("commentList");
     %>
    <table width="781" height="329" border="0">
      <tr>
        <td height="30"><div align="center"><%=blog.getTitle()%></div></td>
      </tr>
      <tr>
        <td height="168"><%=blog.getContent() %></td>
      </tr>
      <tr>
        <td height="50"><%=blog.getCreatedTime() %></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
        <tr>
        <td height="66">
        
     <% for(int i=0;i<list.size();i++){
      Comment comment=(Comment)list.get(i);
      %>
        <table width="672" border="1">
          <tr>
            <td>评论人:<%=comment.getUsername() %></td>
            </tr>
          <tr>
            <td><%=comment.getContent() %></td>
            </tr>
          <tr>
            <td>评论时间</td>
            </tr>
        </table>
        <br></br>
     <%} %>
        <p>&nbsp;</p></td>
      </tr>
      <tr>
        <td height="28"><form id="form1" method="post" action="/blog/servlet/CommentServlet">
        <input type="hidden" name="method" value="add"/>
        <input type="hidden" name="blog_id" value="<%=blog.getId()%>"/>
          <table width="668" border="1">
            <tr>
              <td width="84">评论人:</td>
              <td width="568"><label for="name"></label>
                <input name="name" type="text" id="name" size="20" /></td>
            </tr>
            <tr>
              <td>内容:</td>
              <td><label for=""></label>
                <textarea name="content" cols="80" rows="10" id="content"></textarea></td>
            </tr>
            <tr>
              <td><input type="submit" name="button" id="button" value="提交" /></td>
              <td>&nbsp;</td>
            </tr>
          
          </table>
        </form></td>
      </tr>
      
      
    </table>
    </body>
    </html>
    是,本人小白,  怎么改呀   具体一点 谢谢!
      

  3.   

    找出来了,list 为空~ 添加一个判断语句就OK了!  谢谢!
      

  4.   

    list 为空,类似这种循环 之前都必须有判断的