<jsp:include>和<%@include%>的区别

<%@include%>:页面请求之前预编译,所有代码包含进来之后,一起进行处理,把所有代码合在一起,编译成一个servlet

<jsp:include>:所有代码分别处理,在页面被请求的时候才编译,被编译成多个servlet,页面语法相对独立,处理完成之后再将代码的显示结果(处理结果)组合进来。


JSP中的两种包含页面的方法
第一种:include指令:当JSP转换成Servlet时引入指定文件

<%@ pagecontentType="text/html;charset=GB2312" language="java"errorPage=""%>
<%@ include file="head.jsp"%>
<%@ include file="body.jsp"%>
<%@ include file="tail.jsp"%>
第二种:<jsp:include>动作元素:当JSP页面被请求时引入指定文件
<%@ page contentType="text/html; charset=GB2312"language="java" errorPage=""%>
<jsp:include page="head.jsp"/>
<jsp:include page="body.jsp"/>
<jsp:include page="tail.jsp"/>
第二种方法可以很方便的用<jsp:param>来向所包含页传递参数,方法如下:
<%@ page contentType="text/html; charset=GB2312"language="java" errorPage=""%>
<jsp:include page="head.jsp"/>
<jsp:includepage="body.jsp">
<jsp:param name="uid"value="username"/>
<jsp:param name="pwd"value="password"/>
</jsp:include>
<jsp:includepage="tail.jsp"/>

原文地址:https://www.cnblogs.com/suncj/p/4654894.html