Tomcat 8 JSP javax.servlet.ServletException [英] tomcat 8 jsp javax.servlet.ServletException

查看:71
本文介绍了Tomcat 8 JSP javax.servlet.ServletException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白此错误500和cookie问题,希望有人可以照亮我.

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

当我运行我的requestDispatcher时,我得到了我无法弄清的内部错误500.资源为/WEB-INF/jsp/index.jsp,但在错误消息中显示为/WEB-INF/jsp/cookie ???

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

错误消息

HTTP状态500-javax.servlet.ServletException: javax.servlet.jsp.JspException:java.io.FileNotFoundException: 要求的资源 (/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, 图片/pjpeg,应用程序/x-ms-xbap,应用程序/vnd.ms-excel, application/vnd.ms-powerpoint,application/msword,/, user-agent = Mozilla/5.0(兼容; MSIE 9.0; Windows NT 6.2; Win64; x64;三叉戟/7.0; ASU2JS),accept-encoding = gzip,放气, ua-cpu = AMD64})不可用

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

我的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>

我的文件树

我也没有在程序中使用任何cookie,所以消息中显示的cookie是标准cookie?

Also i dont use any cookies in my program, so the cookie it displays in the message is a standard cookie?

只是确保我确实存在requestDispatcher 确实的文件

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.

编辑.添加了servlet代码

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

}

推荐答案

在使用它们之前,请确保在JSP中导入了JSTL库.

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

即将此添加到index.jsp

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

在呼叫此行之前:

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

这篇关于Tomcat 8 JSP javax.servlet.ServletException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆