这是我的页面
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ page import= "java.sql.*"%>
<html>
<head>
<title>分页显示 </title>
</head>
<body>
<center>
<h1>人员列表 </h1>
<hr>
<br>
<%
final String DBDRIVER = "org.git.mm.mysql.Driver";
final String DBURL = "jdbc:mysql://localhost/mldn";
final String DBUSER = "root";
final String DBPASSWORD = "1234";
Connection conn= null;
%>
<%
try{
Class.forName(DBDRIVER);
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
String sql="SELECT id ,uid,name,password from person";
PreparedStatement pstmt = null;
pstmt= conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
%>
<table border="1" width="80%" >
<tr>
<td>编号 </td>
<td>登陆名称 </td>
<td>姓名 </td>
<td>密码 </td>
<td colspan="2">操作 </td>
</tr>
<%
int i=0;
while(rs.next()){
i++;
int id = rs.getInt(1);
String userid = rs.getString(2);
String name = rs.getString(3);
String password = rs.getString(4);
%>
<tr>
<td> <%=id %> </td>
<td> <%=userid %> </td>
<td> <%=name %> </td>
<td> <%=password %> </td>
<td>更新 </td>
<td>删除 </td>
</tr>
<%
}
rs.close();
pstmt.close();
if(i==0){
%>
<tr>
<td colspan = "6">没有任何数据 </td>
</tr>
<%
}
%>
</table>
<%
}
catch(Exception e){
%>
<h1>系统出错!!! </h1>
<%
}
finally{
conn.close();
}
%>
</center>
</body>
</html>
下面是报错内容:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.lang.NullPointerException
org.apache.jsp.list_005fperson_jsp._jspService(list_005fperson_jsp.java:98)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
note The full stack trace of the root cause is available in the Tomcat logs.
--------------------------------------------------------------------------------
------解决方法--------------------------------------------------------
关于这个错误,我也遇到过,当时就是当我每当要打开这个页时,就出现上述的错误,原因,很简单,也就是当你首次加载页时,没有获得有赋的值,出现的空的记录,也许你要是可以的话,去数据加载一笔数据,之后呢,再来试一下!
对于你的问题;我说一点,这是你测试用的吗!如何你刚接触jsp的话,此页的代码可供参考,千万不要经常如此去写东西呀,因为这个代码中,灵活性几乎为零,安全性几乎没有,可读性太差;希望你多接触一此j2ee框架之类的东西,对于写系统应有帮助的!
------解决方法--------------------------------------------------------
很清楚了NullPointerException 某个变量为空你却调用了他的方法/属性