java web做bbs论坛项目中展现帖子的问题 5C

新手跟着视频做一个BBS项目,做到展示帖子的JSP的时候一直报错
type Exception report

message An exception occurred processing JSP page /articleDetail.jsp at line 23

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /articleDetail.jsp at line 23

20: String sql="select*from article where rootid ="+id+"order by pdate asc";
21: Statement stmt=DB.creatStmt(conn);
22: ResultSet rs=DB.executeQuery(stmt, sql);
23: while (rs.next()){
24: Article a=new Article();
25: a.initFromRs(rs);
26: articles.add(a);

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause
java.lang.NullPointerException
org.apache.jsp.articleDetail_jsp._jspService(articleDetail_jsp.java:87)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

这是个啥情况啊,它说23行那里有错,就那个while那里,可是我怎么看都看不出有错误啊

4个回答

An exception occurred processing JSP page /articleDetail.jsp at line 23

java.lang.NullPointerException
23.while(rs.next())
那应该就是你的rs并没有值,请问你是否有DeBug走过这里看下呢?

while (rs.next()){ 在这个前面加一个判断吧rs是否为null 就可以了

看id传进去了吗,数据库名字对吗,因为你的结果集就没有内容

NullPointerException 报这个错,说明 报错的哪一行有个对象值是null ,看看那个对象可能是null,解决他!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐