JSP注意事项
源码
例子
footer.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<h1>我是Footer</h1>
header.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<h1>我是Header</h1>
jsp2.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%@include file="common/header.jsp"%>
<h1>网页主体</h1>
<%@include file="common/footer.jsp"%>
</body>
</html>
测试:
jsp标签
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%--
%@include会将两个页面合二为一 注意页面合并后的冲突(比如两个页面都定义了int i = 10 这种会报错)
--%>
<%@include file="common/header.jsp"%>
<h1>网页主体</h1>
<%@include file="common/footer.jsp"%>
<hr/>
<%--jsp标签
jsp:include 拼接页面 本质还是三个 推荐使用这种,这种不会出现上面的int i=10冲突的情况,因为本质还是三个页面
--%>
<jsp:include page="common/header.jsp"/>
<h1>网页主体</h1>
<jsp:include page="common/footer.jsp"/>
</body>
</html>
本文来自博客园,作者:Cn_FallTime,转载请注明原文链接:https://www.cnblogs.com/CnFallTime/p/15966806.html