简体   繁体   English

Tomcat 8 JSP javax.servlet.ServletException

[英]tomcat 8 jsp javax.servlet.ServletException

I dont understand this error 500 and cookie problem, hoping someone can inlight me. 我不明白此错误500和cookie问题,希望有人可以照亮我。

When i run my requestDispatcher i get an internal erro 500 that i cant figure out. 当我运行我的requestDispatcher时,我得到了我无法弄清的内部错误500。 The ressource is /WEB-INF/jsp/index.jsp but in the error message it says /WEB-INF/jsp/cookie??? 资源为/WEB-INF/jsp/index.jsp,但在错误消息中显示为/ WEB-INF / jsp / cookie?

The error message 错误讯息

HTTP Status 500 - javax.servlet.ServletException: javax.servlet.jsp.JspException: java.io.FileNotFoundException: The requested resource (/MyNewRandomBlog1.0/WEB-INF/jsp/{cookie=JSESSIONID=4724BBA140EA29EFF07AD782C755ED13, cache-control=no-cache, connection=Keep-Alive, host=localhost:8080, accept-language=da,en-US;q=0.7,en;q=0.3, accept=image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, / , user-agent=Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.2; Win64; x64; Trident/7.0; ASU2JS), accept-encoding=gzip, deflate, ua-cpu=AMD64}) is not available HTTP状态500-javax.servlet.ServletException:javax.servlet.jsp.JspException:java.io.FileNotFoundException:请求的资源(/MyNewRandomBlog1.0/WEB-INF/jsp/{cookie=JSESSIONID=4724BBA140EA29EFF07AD782C755ED13,缓存控制=无缓存,连接=保持活动状态,主机=本地主机:8080,accept-language = da,en-US; q = 0.7,en; q = 0.3,accept = image / jpeg,application / x-ms-application, image / gif,application / xaml + xml,image / pjpeg,application / x-ms-xbap,application / vnd.ms-excel,application / vnd.ms-powerpoint,application / msword, / ,user-agent = Mozilla / 5.0(兼容; MSIE 9.0; Windows NT 6.2; Win64; x64; Trident / 7.0; ASU2JS),accept-encoding = gzip,deflate,ua-cpu = AMD64})不可用

My web.xml 我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>MyNewRandomBlog1.0</display-name>
  <welcome-file-list>
    <welcome-file>frontpage</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>intname</servlet-name>
    <servlet-class>dk.danicait.servlets.FrontpageCreation</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>intname</servlet-name>
    <url-pattern>/frontpage</url-pattern>
  </servlet-mapping>
</web-app>

My file tree 我的档案树

在此处输入图片说明

Also i dont use any cookies in my program, so the cookie it displays in the message is a standard cookie? 我也没有在程序中使用任何cookie,因此消息中显示的cookie是标准cookie?

Just to make sure that the file for the requestDispatcher really exist i did 只是为了确保requestDispatcher的文件确实存在,我确实

String test = sc.getResource("/WEB-INF/jsp/index.jsp").toString();

Which works fine getting the ressource url. 获得资源URL可以正常工作。

Edit. 编辑。 Added servlet code 添加了servlet代码

public class FrontpageCreation extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext sc = getServletContext();

//      Set request attributes
        request.setAttribute("header", sc.getResource("/includes/nav.jsp").toString());
        request.setAttribute("footer", sc.getResource("/includes/footer.jsp").toString());

//      Request dispatcher
        getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp").forward(request, response);
    }

}

The problem was that in 问题是

request.setAttribute("header", sc.getResource("/includes/nav.jsp").toString());
request.setAttribute("footer", sc.getResource("/includes/footer.jsp").toString());

Where i try and pass these values to 我在哪里尝试将这些值传递给

<c:import url="${header}"/>
<c:import url="${footer}"/>

in the index.jsp page, where i believe the import statement does not understand the formatting of the values passed. 在index.jsp页面中,我相信import语句不理解所传递值的格式。 And theirby gives a error 500 message. 并且他们由此给出错误500消息。

Ensure you are importing the JSTL libraries in your JSP before using them 使用它们之前,请确保在JSP中导入了JSTL库。

ie add this at the top of your index.jsp 即将其添加到index.jsp的顶部

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

before calling this line: 在呼叫这条线之前:

<c:import url="${header}"/>

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

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