我具有这样的目录结构:
试图像这样在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}
是您的应用程序的当前contextPath是comediansapp,因此它将尝试在路径/ comediansapp / shared / header.jsp
请检查:https://stackoverflow.com/a/5850406/4325878
我尝试的完整示例:
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>