我在我的layout.sp中包含了一个header.jsp,但它没有反射(reflect)在浏览器中,并且即使在刷新缓存后也尝试了mozilla和ie..
header.jsp内容---
<h1>Login Application</h1>
layout.jsp内容--
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator"%>
<%@page contentType="text/html; charset=UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div>
<jsp:include page="/WEB-INF/includes/header.jsp"/>
</div>
<div ><decorator:body /></div>
</body>
</html>
最佳答案
因为它在WEB-INF目录下。
HTTP 服务器无法访问 WEB-INF 中的所有内容。 jsp:include
通过向服务器发出 HTTP 请求来调用,但目标文件不允许提供服务,因此您什么也得不到。
如果您确实想按原样使用该文件,可以使用:
<%@ include file="/WEB-INF/includes/header.jsp" %>
因为这将在编译时进行评估,并且编译器能够访问该文件。
或者您可以将 jsp 移动到 Web 服务器可访问的文件中,例如 /includes/
,它是 WEB-INF 的同级文件。
<jsp:include page="/includes/header.jsp"/>
此外,请确保该文件具有适当的权限,以便服务器可以访问它。
关于Java header 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1151748/