0

我有我的 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)
4

1 回答 1

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 代码的注释)

于 2013-01-13T22:44:13.740 回答