include静态包含和动态包含

include静态包含

index3.jsp

<body>


<%@ include file="include/head.jsp" %>
body>

include/head.jsp

去掉七七八八的冗余东西,写utf-8那些是为了中文不乱码,接下来的那些就相当于一个html嵌套进index3.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<a href="#">双十一入口a>
<%
    out.print("这是头部!");
%>

这里写图片描述

相当于

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>

<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title heretitle>
head>
<body>


<a href="#">双十一入口a>
<%
    out.print("这是头部!");
%>
body>
html>

include动态包含

test.jsp

<body>
<h1>动态包含h1>



 
<jsp:include page="/include/head.jsp">jsp:include>
<hr>

body>

include/head.jsp

去掉七七八八的冗余东西,写utf-8那些是为了中文不乱码,接下来的那些就相当于一个html嵌套进index3.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<a href="#">双十一入口a>
<%
    out.print("这是头部!");
%>

include静态包含和动态包含_第1张图片

你可能感兴趣的:(Java)