tomcat 8 jsp javax.servlet.ServletException

偶尔善良 提交于 2019-12-25 02:55:29

问题


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);
    }

}

回答1:


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.




回答2:


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

i.e. 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}"/>


来源:https://stackoverflow.com/questions/29015734/tomcat-8-jsp-javax-servlet-servletexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!