jsp报java.lang.NullPointerException

java.lang.NullPointerException

jsp报错日志在另外了一个单独的文件,jsp错误类型很多

后台日志无报错,核查是jsp报空指针:
一:jsp写java代码空指针1

org.apache.jasper.JasperException: An exception occurred processing JSP page /Index.jsp at line 40
37: %>
38:
39: <%
40: List<Category> categories = CategoryService.getInstance().getCategories();
41: List<Category> topCategories = getTopCategories(categories);
42: %>
43: <html>

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.bjsxt.shopping.util.filter.IPFilter.doFilter(IPFilter.java:31)

root cause

java.lang.NullPointerException
com.bjsxt.shopping.category.CategoryService.getCategories(CategoryService.java:102)
org.apache.jsp.Index_jsp._jspService(Index_jsp.java:95)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.bjsxt.shopping.util.filter.IPFilter.doFilter(IPFilter.java:31)

根据以下定位到jsp40line

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

测试得知

CategoryService.getInstance()为获取到对象,null.getCategories();报错引起;

解决方案:

对CategoryService.getInstance()获取对象判断,不为null时在进行逻辑处理;

二:jsp写java代码空指针2

在ie中打开这个jsp网页时,就一直报错
org.apache.jasper.JasperException: An exception occurred processing JSP page /reading.jsp at line 34

31: <%
32: //通过传来的ID提取学生资料
33: Connection conn = linejdbc.getopenConnection();
34: PreparedStatement s = conn.prepareStatement
35: ("select * from student where S_id=? and S_psw=?");
36:
37: s.setString(1,userNow);

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:515)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:426)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

root cause

java.lang.NullPointerException
org.apache.jsp.reading_jsp._jspService(reading_jsp.java:104)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.

根据以下定位到jsp34line

PreparedStatement s = conn.prepareStatement

conn为null引起的,未获取到连接;

数据库连接的方法有问题! 排查数据库连接解决

检查哪一步引起的报错

还可bai以去tomcat安装目录下的: \work\Catalina\localhost这个目录下找到你的项目文件夹
然后找到reading_jsp.java这个文件的104行,去检查错误!

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页