答:动态INCLUDE用jsp:include动作实现
<jsp:include page="included.jsp" flush="true" />它总是会检查所含文件中的变化,适合用于包含动态页面,并且可以带参数
<%@ include file="included.htm" %> 静态INCLUDE用include伪码实现,定不会检查所含文件的变化,适用于包含静态页面
1. 静态include的结果是把其他jsp引入当前jsp,两者合为一体
动态include的结构是两者独立,直到输出时才合并( 看看jsp生成的java文件就可以知道了)
2.正是因为这样,动态include的jsp文件独立性很强,是一个单独的jsp文件,需要使用的对象,页面设置,都必须有自己创建,当然,还好它和include它的页面的request范围是一致的.
最后看老q外写的
When you use <jsp:include>, it executed the target in a separate request, and then includes the output in the including JSP. It doesn’t include the source of the included target, it includes the output. The means by which that target output is generated is lost.
To do what you’re trying to do, you need to use <% include %> directives:
<%@ include file="/WEB-INF/jsp/include/header.jsp" %>This will incline the literal text of header.jsp into your page. Of course, by doing that, you can no longer pass parameters to it, so you’d need to set that as a page context attribute (e.g. using <c:set>… but of course you can’t use <c:set> until you’ve done your include…).
Essentially, it’s not really worth the hassle. Taglib declarations are annoying boilerplate, but hard to get rid of.