包含指令include

5.1静态包含

先包含,然后再编译处理。只是简单把代码全部整合在一起。

语法:<%@include file="要包含的文件路径"%>

例:

info.htm

info.inc

<%="info.jsp"%>

<%@ page contentType="text/html" pageEncoding="GBK"%>


	include


	

静态包含操作

<%@include file="info.htm"%> <%@include file="info.jsp"%> <%@include file="info.inc"%>



5.2动态包含

语法1:不传递参数

={要包含的文件路径|<%=表达式%>}flush=true|false />

语法2:传递参数

<jsp:include page={要包含的文件路径|<%=表达式%>}flush=true|false

    参数名称 value=参数内容/>

    多个参数

例:

<%@ page contentType="text/html" pageEncoding="GBK"%>


	include


<%
	String username = "zhengzengguo";
%>
	

动态包含并传递参数

" />
<%@ page contentType="text/html" pageEncoding="GBK"%>

参数一:<%=request.getParameter("name")%>

参数二:<%=request.getParameter("info")%>


注意:

若出现文件定义变重名时,静态包含会发生错误,因为静态包含只是先整合再编译,会提示重命名。而动态包含则可以正常执行,因为动态包含是先编译再合并,故能正常执行。所以动态包含更加方便,应常使用动态包含。



以上内容参考JAVAWEB开发实战经典(名师讲坛)