使用JSP / Servlet的NullPointerException

时间:2013-01-13 21:59:50

标签: java jsp tomcat servlets

我的doGet为:

protected void doGet(HttpServletRequest request, 
        HttpServletResponse response)
        throws IOException, ServletException{


    String resourceIDstr = request.getParameter("ResourceID");
    int resourceID = Integer.valueOf(resourceIDstr);

    Resource resourceToLend  =  ResourceModule.getInstance()
                                .getResourceByID(Integer.valueOf(resourceID));



    request.setAttribute("resourceToLent", resourceToLend);

    request.setAttribute("innerTab", "LendResource.jsp");
    getServletConfig().getServletContext()
                    .getRequestDispatcher("/WEB-INF/jsp/admin/resourcelend.jsp")
                    .forward(request, response);
}

每当我将任何GET请求转发给此servlet时,它都不会将请求转发给JSP,而是抛出异常:

HTTP Status 500 - org.apache.jasper.JasperException: 
java.lang.NullPointerException

奇怪的是,这个特定的JSP正被其他servlet使用而没有任何问题,这个特殊的servlet抛出了异常。我试图找到异常的可能原因。

提前致谢。

更新:

org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
servlet.TempResourceLendServlet.doGet(TempResourceLendServlet.java:37)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
org.apache.jsp.WEB_002dINF.jsp.admin.resourcelend_jsp._jspService(resourcelend_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
servlet.TempResourceLendServlet.doGet(TempResourceLendServlet.java:37)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.lang.NullPointerException
org.apache.jsp.WEB_002dINF.jsp.admin.LendResource_jsp._jspService(LendResource_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
org.apache.jsp.WEB_002dINF.jsp.admin.resourcelend_jsp._jspService(resourcelend_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
servlet.TempResourceLendServlet.doGet(TempResourceLendServlet.java:37)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

1 个答案:

答案 0 :(得分:3)

正如asgoth所说,你应该在问题中提供你的jsp,而不是servlet。

此外,您的根本原因堆栈跟踪包含一行

org.apache.jsp.WEB_002dINF.jsp.admin.resourcelend_jsp._jspService(resourcelend_jsp.java:114)

这是指你的jsp已经变成的自动创建的servlet。你会在tomcat的工作文件夹中找到它 - 因为它是自动生成java代码,你必须做一些映射工作,但它应该或多或少地自我解释你的jsp中第114行引用的内容。有了这个,你可以找到自己的根本原因。 (上次我看过这些文件,他们有一些注释引用了等效的jsp代码)