gpt4 book ai didi

java - tomcat 8 jsp javax.servlet.ServletException 异常

转载 作者:行者123 更新时间:2023-11-28 23:32:11 24 4
gpt4 key购买 nike

这个error 500和cookie的问题我不太明白,希望高人指点。

当我运行我的 requestDispatcher 时,我得到一个我无法弄清楚的内部错误 500。资源是/WEB-INF/jsp/index.jsp 但在错误消息中它说/WEB-INF/jsp/cookie???

错误信息

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>

我的文件树

enter image description here

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

我只是为了确保 requestDispatcher 的文件真的存在

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

获取资源 url 效果很好。

编辑。添加了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);
}

}

最佳答案

问题是在

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

我在哪里尝试将这些值传递给

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

在 index.jsp 页面中,我认为导入语句不理解传递值的格式。他们给出了错误 500 消息。

关于java - tomcat 8 jsp javax.servlet.ServletException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29015734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com