空指针异常org.apache.jasper.JasperException: java.lang.NullPointerException
运行JSP页面出错:org.apache.jasper.JasperException:AnexceptionoccurredprocessingJSPpage/disp...
运行JSP页面出错:org.apache.jasper.JasperException: An exception occurred processing JSP page /displayBlogList.jsp at line 14
11: <%
12: List list = (List) request.getAttribute("list");
13: Blog blog = null;
14: for (int i = 0; i < list.size(); i++) {
15: blog = (Blog) list.get(i);
16: System.out.println(blog.getId() + "," + blog.getTitle() + ","
17: + blog.getCreatedTime());
我的GetBlogListServlet.java中的
try {
// 添加博文的SQL语句
String sql = "select id,title,content,createdtime from blog order by id desc";
// DButils中核心类,生成对象时传递数据源对象
QueryRunner qr = new QueryRunner(ds);
List list=(List)qr.query(sql,new BeanListHandler(Blog.class));
request.setAttribute("List", list);
request.getRequestDispatcher("/displayBlogList.jsp").forward(request,
response);
} catch (SQLException e) {
e.printStackTrace(); 展开
11: <%
12: List list = (List) request.getAttribute("list");
13: Blog blog = null;
14: for (int i = 0; i < list.size(); i++) {
15: blog = (Blog) list.get(i);
16: System.out.println(blog.getId() + "," + blog.getTitle() + ","
17: + blog.getCreatedTime());
我的GetBlogListServlet.java中的
try {
// 添加博文的SQL语句
String sql = "select id,title,content,createdtime from blog order by id desc";
// DButils中核心类,生成对象时传递数据源对象
QueryRunner qr = new QueryRunner(ds);
List list=(List)qr.query(sql,new BeanListHandler(Blog.class));
request.setAttribute("List", list);
request.getRequestDispatcher("/displayBlogList.jsp").forward(request,
response);
} catch (SQLException e) {
e.printStackTrace(); 展开
4个回答
展开全部
很明显,你很粗心,大小写没有注意到。
List list = (List) request.getAttribute("list");
request.setAttribute("List", list);
第二行放进去的是List,而取出来的时候是list,所以是空指针
List list = (List) request.getAttribute("list");
request.setAttribute("List", list);
第二行放进去的是List,而取出来的时候是list,所以是空指针
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
List list=(List)qr.query(sql,new BeanListHandler(Blog.class));
没有检索出数据时,返回可能是空,
那么request.setAttribute("List", list);
request中放的也会为空
jsp中的for循环,list.size(); 也就会有空指针异常了。
希望能帮到你!
没有检索出数据时,返回可能是空,
那么request.setAttribute("List", list);
request中放的也会为空
jsp中的for循环,list.size(); 也就会有空指针异常了。
希望能帮到你!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
request.setAttribute("List", list);
List list = (List) request.getAttribute("list");
好叻.自己看吧
List list = (List) request.getAttribute("list");
好叻.自己看吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询