很久以来,都知道JSP其实就是Servlet,今天心血来潮,想把里面的具体代码看一遍,并记录心得。
一个编译好的JSP类如下:
public final class index_jsp extends HttpJspBase
implements JspSourceDependent
//上述类为index.jsp被编译后得到的类
//HttpJspBase是extends HttpServlet的一个类
//JspSourceDependent是一个接口,只声明了一个方法、、getDependants(),返回当前page所依赖的文件的名称,文件包括以下几种
//1) files that are included by page directives
//2) files that are included by include-prelude and include-coda in jsp:config
//3) files that are tag files and referenced
//4) TLDs referenced
其核心方法为:
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
.
}
该方法重载HttpJspBase中的_jspService方法,进行页面解析,包括对scriptlet的加载,html的生成,自定义Tag的解析等等
HttpJspBase的service再对_jspService再进行调用,最终生成HTML页面