在我的Web应用程序中,我得到了包含默认标头内容的Header.jsp文件.我在所有其他页面中使用jsp:include标签将其包含在每个页面的body标签内.
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
这样做是否有效?