How Tomcat runs JSP: A test tool, and a tomcatjsp Test Tool

Source: Internet
Author: User

How Tomcat runs JSP: A test tool, and a tomcatjsp Test Tool

I recently read JSP/Servlet in my free time. I used to only know how to use JSP, But I know little about its running principle. Now I want to take some notes for reference.

First, briefly describe the running process, and then make a brief analysis based on the Tomcat source code.

JSP running process:

Step 1: translate JSP files into servlet Source Code;

Step 2: Compile the servlet Source code into a bytecode file;

Step 3: load the bytecode and instantiate and initialize it;

Step 4: Call the service method to provide services;

A Brief Analysis of the source code is as follows:

1. Several important files involved in source code

JspServlet. java, JspServletWrap. java, JspRuntimeContext. java, Compiler. java, JDTCompiler. java (AntCompiler. java)

2. Detailed code analysis

JspServlet involves two important methods: service method and serviceJspFile. service method is mainly used to obtain the requested JSP resource path, and serviceJspFile is mainly used to build JspServletWrap.

JspRuntimeContext mainly provides JspServletWrap containers (using HashMap sets ).

Compiler is mainly used to translate JSP files and compile them into bytecode. The specific bytecode generation implementation is implemented by its sub-classes (using the template method design mode ).

JDTCompiler (AntCompiler) is mainly used to generate bytecode files.

JspServletWrap is mainly used to instantiate the Servlet and call init for initialization, and call the servlet service method to process requests.

 

Further exploration into the specific implementation details. I will write this article today. My level is limited. If you have any questions, please advise!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.