一、静态包含
<%@ include file=”” > 就是静态包含
file属性指定你要包含的jsp页面的路径
地址中第一个斜杠表示为http://ip:port/工程路径 映射到代码的web目录
实质:就是把被包含的jsp页面的代码拷贝到包含的位置执行输出
main.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head><title>Title</title></head><body>头部信息<br>主体信息<br><%--<%@ include file="" 就是静态包含file属性指定你要包含的jsp页面的路径地址中第一个斜杠表示为http://ip:port/工程路径 映射到代码的web目录--%><%@include file="/include/footer.jsp"%></body></html>
footer.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head><title>Title</title></head><body>页脚信息<br></body></html>
二、动态包含
<jsp:include page=""></jsp:include> 动态包含<br /> page属性是指你要包含的jsp页面的路径<br /> 动态包含可以像静态包含一样,把被包含的内容执行输出到包含的位置<br /> 特点:<br /> 1.动态包含会把被包含的jsp页面也翻译成java代码<br /> 2.动态包含底层代码使用一个代码调用被包含的jsp页面执行输出<br /> 3.动态包含可以传递参数:
main.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head><title>Title</title></head><body>头部信息<br>主体信息<br><jsp:include page="/include/footer.jsp"><jsp:param name="userName" value="wyb"/></jsp:include></body></html>
foot.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head><title>Title</title></head><body>页脚信息<br><%=request.getParameter("userName")%></body></html>
jsp动态包含底层原理图

但是,大多数情况使用静态包含就可以了
三、请求转发
方式一
方式二 <% request.getRequestDispatcher(“/js/scope2.jsp”).forward(request,response); %>
两个没有区别
