dispatcher.forward()生成HTTP 500

时间:2014-04-10 21:46:56

标签: java http tomcat servlets relative-path

考虑层次结构:

enter image description here

我将JSP从WEB-INF移到了src文件夹。但是当我尝试dispatcher.forward()时,我得到了:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
    controller.LoginPage.doPost(LoginPage.java:214)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.50 logs.

Apache Tomcat/7.0.50

指定的异常发生在以下行中:

 String addressPath = "/../view/admin/adminPage.jsp";
 RequestDispatcher dispatcher = request.getRequestDispatcher(addressPath);
 dispatcher.forward(request, response);

如何修复路径?

由于

1 个答案:

答案 0 :(得分:1)

您的JSP位于源文件夹中的事实似乎表明它将放在

/WEB-INF/classes/view/admin/

这真的不在哪里

String addressPath = "/../view/admin/adminPage.jsp";

指向它。

如果Servlet容器无法为给定路径返回getRequestDispatcher,则

null将返回RequestDispatcher

JSP不应该在/WEB-INF/classes之下。将它们放在像/WEB-INF/jsp/view这样的专用文件夹中,然后在那里访问它们。

然后您可以使用

访问它
String addressPath = "/WEB-INF/jsp/view/admin/adminPage.jsp";