【发布时间】:2014-08-01 05:02:51
【问题描述】:
在我的 Web 应用程序中,我得到了包含默认标题内容的 Header.jsp 文件。我在所有其他页面中使用 jsp:include 标记将其包含在每个单独页面的正文标记中。
Header.jsp 包含它自己的 HEAD 标记来指定默认元标记、链接样式表、脚本和一些 HTML 元素。同时,我将在所有其他单独的页面中使用另一组 HEAD 标记来定义标题、页面特定脚本和样式表。
例如:
Header.jsp
<head>
<link rel="shortcut icon" href="<%=request.getContextPath()%>/images/favicon.ico" type="image/x-icon" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<script src="js/jquery.js"></script>
<link rel=stylesheet type="text/css" href="dashboard.css" >
</head>
<h2>Dashboard</h2>
Main.jsp
<!DOCTYPE html>
<html>
<head>
<title>Main page</title>
<script src="main.js"></script>
</head>
<body>
<jsp:include page="Header.jsp" flush="true" />
.....
other HTML contents specific to main page
.....
</body>
</html>
这样做是否有效?
【问题讨论】:
-
您不能在
<head>中包含jsp 文件,而只使用您需要的行,例如<meta、<script和<link吗?我对 JSP 不太了解,如果我错了,请纠正我。 -
当然你“可以”。真正的问题是:'有两个头部标签是否有效?'。答案是否定的,遵循 W3C 规范