<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="entity.Student"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<table align="center" border="1" cellpadding="0" cellspacing="0" width="650">
<caption>
<h2>学生信息</h2>
<a href="insertStudent.jsp">添加学生</a>
</caption>
<tr style="background-color:green">
<th>id</th>
<th>name</th>
<th>sex</th>
<th>weight</th>
<th>bri</th>
<th>操作</th>
</tr>
<%
Object obj=request.getAttribute("list");
List<Student> stus=(List<Student>)obj;
for(Student s : stus){
%>
<TR>
<td><%=s.getSid()%></td>
<td><%=s.getSname()%></td>
<td><%=s.getSex()%></td>
<td><%=s.getWeight()%></td>
<td><%=s.getBri()%></td>
<td>
<a href="">删除</a>
<a href="">修改</a>
</td>
</TR>
<%
}
%>
</table>
</body>
</html>
____________________________________________
package Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import entity.Student;
public class StudentDao {
public List queryStudentAll() {
Connection conn = BaseDao.getConn();
Statement stat =null;
ResultSet rs = null;
ArrayList<Student> list = new ArrayList<Student>();
try {
stat = conn.createStatement();
rs = stat.executeQuery("select * from student");
while (rs.next()) {
Student s = new Student();
s.setSid(rs.getInt("sid"));
s.setSname(rs.getString("sname"));
s.setSex(rs.getString("sex"));
s.setWeight(rs.getInt("weight"));
s.setBri(rs.getDate("bri"));
list.add(s);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
BaseDao.close(rs,stat, conn);
}
return list;
}
_________________________________________________
package servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Dao.StudentDao;
public class QueryStudentServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse arg1)
throws ServletException, IOException {
StudentDao sd=new StudentDao();
List list= sd.queryStudentAll();
req.setAttribute("list",list);
req.getRequestDispatcher("index.jsp").forward(req, arg1);
}
}
为什么报java.lang.NullPointerException,oracle数据库也没事,是哪里没配置好吗?
大佬帮我解决一下。
错误———错误————错误————————错误————————错误
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:556) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException org.apache.jsp.index_jsp._jspService(index_jsp.java:128) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339) javax.servlet.http.HttpServlet.service(HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
你倒是把异常信息贴出来啊,不贴出来怎么知道哪里有问题
– 青雉 6年前@青雉: 我把错误放在题目下面了
– 寒兔 6年前