简体   繁体   English

dispatcher.forward()产生HTTP 500

[英]dispatcher.forward() produces HTTP 500

Consider the hierarchy : 考虑层次结构:

在此处输入图片说明

I moved my JSPs from WEB-INF to the src folder .However when I try to dispatcher.forward() , I get : 我将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

The specified exception occurs in the lines : 指定的异常发生在各行中:

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

How can I fix the path ? 我该如何解决?

Thanks 谢谢

The fact that your JSP is in a source folder seems to indicate that it will be placed in 您的JSP在源文件夹中的事实似乎表明它将被放置在

/WEB-INF/classes/view/admin/

Which is really not where 哪个真的不在哪里

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

is pointing it to. 指向它。

getRequestDispatcher returns null if the Servlet container cannot return a RequestDispatcher for the given path. 如果Servlet容器无法为给定路径返回RequestDispatcher ,则getRequestDispatcher返回null

JSPs shouldn't really be under /WEB-INF/classes . JSP不应真正位于/WEB-INF/classes Put them in a dedicated folder like /WEB-INF/jsp/view and access them there. 将它们放在/WEB-INF/jsp/view等专用文件夹中,然后在其中访问它们。

You could then access it with 然后,您可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM