Jsp 包括不工作:找不到文件,状态 500
Jsp include not working: file not found, status 500
我有这样的目录结构:
正在尝试将 header.jsp
包含在 home.jsp
中,如下所示:
<%--
Created by IntelliJ IDEA.
User: Irina
Date: 31.03.20
Time: 20:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="${pageContext.request.contextPath}/shared/header.jsp" />
<a href="${pageContext.request.contextPath}/login">Login</a>
<a href="${pageContext.request.contextPath}/signup">Signup</a>
</body>
</html>
失败并出现 org.apache.jasper.JasperException: javax.servlet.ServletException: File [/comediansapp/shared/header.jsp] not found
错误。我做错了什么?
提供相对于当前页面的路径。
尝试:
<jsp:include page="shared/header.jsp"/>
${pageContext.request.contextPath}
是您的应用程序的当前上下文路径是 comediansapp 因此它将尝试在路径 /comediansapp/shared/header.jsp
请检查:
我试过的完整示例:
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="shared/header.jsp" />
<a href="${pageContext.request.contextPath}/login.jsp">Login</a>
<a href="${pageContext.request.contextPath}/signup.jsp">Signup</a>
</body>
</html>
shared/header.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<nav style="height:50px; background:red;">
<strong> JSP!!! </strong>
</nav>
工作示例:
我有这样的目录结构:
正在尝试将 header.jsp
包含在 home.jsp
中,如下所示:
<%--
Created by IntelliJ IDEA.
User: Irina
Date: 31.03.20
Time: 20:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="${pageContext.request.contextPath}/shared/header.jsp" />
<a href="${pageContext.request.contextPath}/login">Login</a>
<a href="${pageContext.request.contextPath}/signup">Signup</a>
</body>
</html>
失败并出现 org.apache.jasper.JasperException: javax.servlet.ServletException: File [/comediansapp/shared/header.jsp] not found
错误。我做错了什么?
提供相对于当前页面的路径。 尝试:
<jsp:include page="shared/header.jsp"/>
${pageContext.request.contextPath}
是您的应用程序的当前上下文路径是 comediansapp 因此它将尝试在路径 /comediansapp/shared/header.jsp
请检查:
我试过的完整示例:
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<jsp:include page="shared/header.jsp" />
<a href="${pageContext.request.contextPath}/login.jsp">Login</a>
<a href="${pageContext.request.contextPath}/signup.jsp">Signup</a>
</body>
</html>
shared/header.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<nav style="height:50px; background:red;">
<strong> JSP!!! </strong>
</nav>
工作示例: