知道为什么从servlet转发到JSP可能会导致错误500吗?

这是代码的这一部分:

session.removeAttribute("cdoChosen");
    String nextJSP = "/EndLandingPage.jsp";
     System.out.println("Redirecting to the final landing page with results.");

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
    dispatcher.forward(request,response);


我正在许多其他servlets中使用这种转发,没有问题。该应用程序的执行日志未显示任何内容,最后一行是:

Redirecting to the final landing page with results.


您可能在上面的代码中看到的是System.out.println的结果。

我正在使用Tomcat v7和来自AWS的Ubuntu OS。

我要说的唯一区别是我没有将servlet分配给JSP。参见web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Visma_UploadInterface</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>LoginServlet</servlet-name>
        <servlet-class>servlets.LoginServlet</servlet-class>
</servlet>
    <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/main/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>MainPageServlet</servlet-name>
        <servlet-class>servlets.MainPageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MainPageServlet</servlet-name>
        <url-pattern>/mainPage/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>MappingServlet</servlet-name>
        <servlet-class>servlets.MappingServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MappingServlet</servlet-name>
        <url-pattern>/mapping/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>ListImportServlet</servlet-name>
        <servlet-class>servlets.ListImportServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ListImportServlet</servlet-name>
        <url-pattern>/listImport/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>RejectedRecordsServlet</servlet-name>
        <servlet-class>servlets.RejectedRecordsServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>RejectedRecordsServlet</servlet-name>
        <url-pattern>/rejectedRecords/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>UploadServlet</servlet-name>
        <servlet-class>servlets.UploadServlet</servlet-class>

    </servlet>



</web-app>


我的doPost()

protected void doPost(HttpServletRequest request, HttpServletResponse response) {
        try{
            String fieldMapping = request.getParameter("fieldMapping");
            HttpSession session = request.getSession();
            String fileName = (String) session.getAttribute("fileName");
            EloquaListImportToCdo listImportClass = new EloquaListImportToCdo(fieldMapping, session, fileName);
            listImportClass.importList();
            String pathStr = (String) session.getAttribute("filePath");
            Path path = Paths.get(pathStr);
            try {
                Files.delete(path);
            } catch (NoSuchFileException x) {
                System.err.format("%s: no such" + " file or directory%n", path);
            } catch (DirectoryNotEmptyException x) {
                System.err.format("%s not empty%n", path);
            } catch (IOException x) {
                // File permission problems are caught here.
                System.err.println(x);
            }
            session.removeAttribute("cdoChosen");
            String nextJSP = "EndLandingPage.jsp";
            System.out.println("Redirecting to the final landing page with results.");

            RequestDispatcher dispatcher = request.getRequestDispatcher(nextJSP);
            dispatcher.forward(request,response);
        }catch (Exception ex){
            System.out.println(ex.toString());
        }
    }


任何想法?

最佳答案

RequestDispatcher dispatcher =
        request.getRequestDispatcher("EndLandingPage.jsp");


如果使用相对路径,则必须使用HttpServletRequest.getRequestDispatcher()ServletContext.getRequestDispatcher()不允许。

09-30 15:28
查看更多