简体   繁体   中英

tomcat 8 jsp javax.servlet.ServletException

I dont understand this error 500 and cookie problem, hoping someone can inlight me.

When i run my requestDispatcher i get an internal erro 500 that i cant figure out. The ressource is /WEB-INF/jsp/index.jsp but in the error message it says /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

My 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?

Just to make sure that the file for the requestDispatcher really exist i did

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

Which works fine getting the ressource url.

Edit. Added servlet code

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. And theirby gives a error 500 message.

Ensure you are importing the JSTL libraries in your JSP before using them

ie add this at the top of your index.jsp

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

before calling this line:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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