javaee-include指令原理
? ? ? ? ? ?include指令,即<%@ include file="included.jsp"%>表面看起来和RequestDispatcher对象的include有关系。而实际上并非如此。对于<%@ include file="included.jsp"%>指令,其更多的是给翻译引擎(jsp->servlet源文件)来看的,翻译引擎在发现后,直接将其指定的?include指令页面一并翻译到servlet中去。
?
?
1. jsp页面如下:
?
1.1 including.jsp 用于引用其他页面
?
?
<%@ page pageEncoding="GB18030"%><!-- 通过源代码查看,下面这个标签和servlet中的RequestDispatcher 的include没有半点关联 --><%@ include file="included.jsp"%><%out.println("before exception!");int x = 1 / 2;out.println("after exception!");%>
?
1.2 included.jsp 被引用页面
?
?
<%@ page pageEncoding="GB18030"%><%out.println("哥被included了!");%>
?
2. apache-tomcat-6.0.29翻译的servlet的部分源代码
?
?
out.write("\r\n"); out.println("哥被included了!"); out.write("\r\n"); out.write("\t "); out.write('\r'); out.write('\n'); out.println("before exception!"); int x = 1 / 0; out.println("after exception!");
?
?呵呵,明白了吧。记得过去学习c++时,也有给类似的功能,呵呵。