| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1742 人关注过本帖
标题:把数据库数据显示在JSP界面报错
只看楼主 加入收藏
EMMMM
Rank: 1
等 级:新手上路
帖 子:32
专家分:0
注 册:2017-9-16
结帖率:75%
收藏
 问题点数:0 回复次数:0 
把数据库数据显示在JSP界面报错
不知道为什么,莫名报了一个Iterator的错误,但是我查了一下压根没写错,想不明白为什么,只能求助各位了
代码如下:
display.jsp
<%@page import="org.apache.catalina.User"%>
<%@page import="com.model.Student"%>
<%@ page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>所有学生信息</title>
<jsp:include page="login.jsp"></jsp:include>
<body>
<%
List stus=(List)session.getAttribute("stus");
Iterator iterator=stus.iterator();
%>
<table>
<tr><td>id</td><td>stu_id</td><td>stu_name</td><td>stu_math</td><td>stu_chinese</td><td>stu_english</td></tr>
<%
int i=0;
while(iterator.hasNext())
{
    Student student=(Student)iterator.next();
    %>
        <tr>
    <td><%=student.getStu_id() %></td>
    <td><%=student.getStu_name() %></td>
    <td><%=student.getStu_math() %></td>
    <td><%=student.getStu_chinese() %></td>
    <td><%=student.getStu_english() %></td>
    <td><a href="delete.jsp?id=<%=student.getId() %>">删除</a>
    </tr>
    <%
}
%>
</table>
</body>
</html>
查询功能的函数
    public List<Student> queryAllStu()
    {
        List<Student> stus=new ArrayList<Student>();
        try {
            pStatement=connection.prepareStatement("select *from stu_grade");
            ResultSet rSet=pStatement.executeQuery();
            while (rSet.next())
            {
                Student student=new Student();
                student.setId(rSet.getInt(1));
                student.setStu_id(rSet.getString(2));
                student.setStu_name(rSet.getString(3));
                student.setStu_math(rSet.getString(4));
                student.setStu_chinese(rSet.getString(5));
                student.setStu_english(rSet.getString(6));
                stus.add(student);
            }
            return stus;
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            return null;
        }
    }

报错信息:
严重: Servlet.service() for servlet [jsp] in context with path [/the_experience] threw exception [An exception occurred processing JSP page /display.jsp at line 16

13: <body>
14: <%
15: List stus=(List)session.getAttribute("stus");
16: Iterator iterator=stus.iterator();
17: %>
18: <table>
19: <tr><td>id</td><td>stu_id</td><td>stu_name</td><td>stu_math</td><td>stu_chinese</td><td>stu_english</td></tr>


Stacktrace:] with root cause
java.lang.NullPointerException
    at org.apache.jsp.display_jsp._jspService(display_jsp.java:132)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1152)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.(NioEndpoint.java:1539)
    at org.apache.tomcat.(NioEndpoint.java:1495)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

搜索更多相关主题的帖子: JSP Iterator apache Student java 
2018-11-10 13:15
快速回复:把数据库数据显示在JSP界面报错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018729 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved