Glassfish Webapp中抛出Java.lang.NullPointerException

时间:2015-11-24 16:41:34

标签: jsp web-applications nullpointerexception glassfish

我正在尝试创建一个在线测验应用程序,并设置了所有我的java类来进行测验,并在控制台中测试它们以确保它们输出我需要的内容。

然而,当我访问我的C1Test.jsp页面时,应该生成一个测验,我得到了glassfish抛出的NullPointerException,在做了一些谷歌搜索之后,我仍然不确定为什么。

可以在下面找到堆栈跟踪,以及我的C1Test.jsp源代码。任何帮助都会非常感激,这是我计算机科学学位的最后一年项目,在修复之前我无法取得任何进展。

提前致谢。

    Info:   Closing WebApplicationContext for namespace 'dispatcher-servlet'startup date [Tue Nov 24 16:32:38 GMT 2015]; parent: Root WebApplicationContext
Info:   WebModule[null] ServletContext.log():Closing Spring root WebApplicationContext
Info:   Closing Root WebApplicationContext: startup date [Tue Nov 24 16:32:37 GMT 2015]; root of context hierarchy
Warning:   StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jsp.C1Test_jsp._jspService(C1Test_jsp.java:101)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:745)

C1Test.jsp源代码:

<%-- 
    Document   : C1 Test
    Created on : Nov 5, 2015, 6:47:35 PM
    Author     : Joe Perkins
--%>
<%@ page language="java" import="Dissertation.*" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>C1 Test</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    </head>

    <body>

        <nav class="navbar navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="HomePage.jsp">EduMath</a>
                </div>

                <div>
                    <ul class="nav navbar-nav">
                        <li><a href="Index.jsp">Home</a></li>
                        <li><a href="C1.jsp">C1 Revision</a></li>
                        <li><a href="C2.jsp">C2 Revision</a></li>
                        <li><a href="SkillsetDeveloper.jsp">Skillset Development</a></li>
                        <li><a href="About.jsp"> About</a></li>
                    </ul>
                </div>
            </div>
        </nav>



        <div class="container">
            <div class="jumbotron">
                <h1>C1 Revision Test</h1>    
            </div>
            <div class="container">
                <%
                    // Retrieve the current quiz question
                    int currQuestion = ((Exam)request.getSession().getAttribute("currentTest")).getCurrentQuestion();
                    System.out.println("Question No. " + currQuestion);
                %>

                Current Question ${sessionScope.quest.questionNo+1} / 10

                <span>${sessionScope.quest.question}</span><br/><br/>

                <form class ="form-horizontal" action="test" method="post">
                    <c:forEach var="choice" items="q${sessionScope.quest.questionOptions}" varStatus = "counter">
                        <input type="radio" name="answer" value="${counter.count}" >${choice}  <br/>
                    </c:forEach> <br />

                    <%
                        if(currQuestion > 0)
                        {
                    %>

                            <input type="submit" name="action" value="previous"/>
                    <%  } %>

                    <%
                        if(currQuestion < 19)
                        {
                            %>

                            <input type="submit" name="action" value ="next"/>
                            <% } %>

                            <input type="submit" name="action" value="Finish Exam"/>
                </form>




                </form>

            </div>
        </div>

    </body>
</html>

编辑:与标记为可能重复的问题不同,我理解NullPointerException的基础,但更多的是寻找关于如何根据堆栈跟踪识别NullPointer来源的一般建议,以及如何最好地设置会话属性。

1 个答案:

答案 0 :(得分:0)

确保在对其内容执行任何操作之前设置了会话属性currentTest