0

那是我在jsp中的代码,当我运行它时会出现如下错误。我正在使用 tomcat 。我真的很想知道这个问题的原因可能是什么?

测试.jsp

<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="admin.User"%>
<%@page import="admin.ConnectionManager"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title> test </title>
</head>
<body>

<div>
        <table>
            <%
            ResultSet rs = User.loadAll(); 
                while (rs.next()) { 
            %> 

            <tr>
               <TH>ID</TH>
               <TH>Name</TH>
               <TH>Surname</TH>
               <TH>Email</TH>

           </tr>
           <tr>
               <td> <%= rs.getInt(1) %> </td>
               <td> <%= rs.getString(2) %> </td>
               <td> <%= rs.getString(3) %> </td>
               <td> <%= rs.getString(4) %> </td>


           </tr>
        </table>
    </div>

       <% 
           } 
       %>
    </body>
</html>

HTTP 状态 500 - java.lang.NullPointerException


type Exception report

message java.lang.NullPointerException

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

exception 

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NullPointerException
    org.apache.jsp.test_jsp._jspService(test_jsp.java:75)
    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:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


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

Apache Tomcat/6.0.36

4

1 回答 1

0

您应该检查 Apache Tomcat 日志,但可能 User.loadAll() 返回 null 设置为 rs 并且 NullPointerException 在 rs.next() 上抛出

顺便说一句,body 和 html 都没有关闭,或者您只是错误地复制了代码。

于 2013-05-07T20:04:35.370 回答