Loading

JSP注意事项

源码
image-20210917114741104
image-20210917183509464

image-20210917183532234

例子

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>

测试:

image-20210917182718104

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>

image-20210917183430249

posted @ 2022-03-05 00:26  Cn_FallTime  阅读(32)  评论(0编辑  收藏  举报