Spring源码分析【7】-Spring 模板页和JSP文件的编译

 2019-10-17 21:50  阅读(1138)
文章分类:Spring boot

org.apache.jasper.servlet.JspServletWrapper.service

20191017100202\_1.png

org.apache.jasper.JspCompilationContext.compile

20191017100202\_2.png

org.apache.jasper.JspCompilationContext.createCompiler

20191017100202\_3.png

org.apache.jasper.compiler.Compiler.isOutDated

判断文件是否存在

20191017100202\_4.png

..\Apache\apache-tomcat-8.0.36\work\Catalina\localhost\ROOT\org\apache\jsp\WEB_002dINF\views目录为空,故意删掉之前编译的jsp类文件

20191017100202\_5.png

返回上一步

20191017100202\_6.png

org.apache.jasper.JspCompilationContext.compile

20191017100202\_7.png

org.apache.jasper.compiler.Compiler.compile

20191017100202\_8.png

org.apache.jasper.compiler.Compiler.compile

20191017100202\_9.png

org.apache.jasper.compiler.Compiler.generateJava

20191017100202\_10.png

这个函数一直往下走到这一步:

20191017100202\_11.png

org.apache.jasper.compiler.Compiler.setupContextWriter

20191017100202\_12.png

jsp生成java类的关键代码

OutputStreamWriter osw = null;

            try {
                osw = new OutputStreamWriter(
                        new FileOutputStream(javaFileName), javaEncoding);
            } catch (UnsupportedEncodingException ex) {
                errDispatcher.jspError("jsp.error.needAlternateJavaEncoding",
                        javaEncoding);
            }

预先生成空文件占位

20191017100202\_13.png

返回

20191017100202\_14.png

org.apache.jasper.compiler.Generator.generate

20191017100202\_15.png

org.apache.jasper.compiler.Generator.generatePostamble

20191017100202\_16.png

到generatePostamble最后一行代码

20191017100202\_17.png

org.apache.jasper.compiler.Generator.genCommonPostamble

20191017100202\_18.png

org.apache.jasper.compiler.ServletWriter.printMultiLn

20191017100202\_19.png

回到genCommonPostamble

20191017100202\_20.png

popIndent

20191017100202\_21.png

回到genCommonPostamble

20191017100202\_22.png

回到generatePostamble

20191017100202\_23.png

回到generate

20191017100202\_24.png

回到generateJava

20191017100202\_25.png

完成整个try过程,文件生成才完成

20191017100202\_26.png

jsp生成的java文件

20191017100202\_27.png

回到compile

20191017100202\_28.png

下一步

20191017100202\_29.png

org.apache.jasper.compiler.JDTCompiler.generateClass

编译.java文件为.class文件

20191017100202\_30.png

下一步

20191017100202\_31.png

下一步

20191017100202\_32.png

下一步

20191017100202\_33.png

下一步

20191017100202\_34.png

下一步

20191017100202\_35.png

下一步

20191017100202\_36.png

下一步

20191017100202\_37.png

终于编译完成

20191017100202\_38.png

回到compile

20191017100202\_39.png

回到compile

20191017100202\_40.png

回到service

20191017100202\_41.png

getServlet

20191017100202\_42.png

第四步

20191017100202\_43.png

(4) Service request

20191017100202\_44.png

service

20191017100202\_45.png

service

20191017100202\_46.png

执行home_jsp.class文件

20191017100202\_47.png

持续后退到doFilter

20191017100202\_48.png

至此一个jsp的编译执行就完成了。


来源:[]()

点赞(0)
版权归原创作者所有,任何形式转载请联系作者; Java 技术驿站 >> Spring源码分析【7】-Spring 模板页和JSP文件的编译

相关推荐