Method for optimizing first access speed of JSP page in Spring Boot
By completing the complete compilation of JSP pages to Java Servlet class bytecode files during the Spring Boot application construction phase, and automatically loading precompiled results at startup, the problem of slow access to JSP pages for the first time is solved, and faster page loading and earlier error detection is achieved.
Patent Information
- Application Number
- CN202510647245.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-08-29
AI Technical Summary
In Spring Boot applications, precompilation of JSP pages is difficult to implement, resulting in slow first access, and traditional solutions increase maintenance costs and performance losses.
Complete compilation of the JSP page to the Java Servlet class bytecode file during the construction phase, generate the same Class file as the runtime compilation, and automatically load the precompiled results through the built-in Tomcat registrant when the application is started, directly call the precompiled bytecode file to avoid the compilation overhead during the first access.
Completely eliminate the compilation overhead of first access, improve the loading speed of JSP pages, reduce the risk of abnormalities in the production environment, and ensure the consistency of precompilation results with runtime compilation.
Smart Images

Figure CN120561393A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of Java Web development, and in particular relates to a method for optimizing the first access speed of a JSP page in Spring Boot. Background Art
[0002] Modern Java Web development frameworks have simplified the development process, especially the development of the Spring framework. Spring Boot is a rapid development platform based on the Spring framework for building independent, production-grade Spring applications. It simplifies the traditional Java Web development process by automatically configuring and embedding containers such as Tomcat.
[0003] JSP (full name: Java Server Pages) is a dynamic web page development technology based on Java technology. It simplifies web application development, especially when creating dynamic web pages. It allows developers to embed Java code in HTML pages and easily generate dynamic web page content by using special tags and expressions, thereby providing users with a richer and more interactive web experience. JSP technology is very useful for creating dynamic web pages. JSP pages exist in the server in the form of JSP files, but the server cannot directly execute JSP files. When the first request for a JSP page arrives at the server, the Servlet container compiles the JSP file into the source code of a Java Servlet class with a file extension of .java (abbreviated as: Java file). The Java Servlet class is a Java class that serves web applications and is used to receive and respond to HTTP requests from web clients. Because the Java Servlet class source code (.java file) cannot be directly executed by the server, it is further compiled into the Java Servlet class bytecode. After the file extension is .class (abbreviated as "Class file"), it is executed by the server (such as the JVM). The Java Servlet class source code is cached in the Servlet container so that it can be called from the cache in subsequent requests, thereby improving page responsiveness. Only when the JSP page changes are the JSP page recompiled and the compiled file saved again. Common Servlet containers include Apache Tomcat.
[0004] There are two types of JSP compilation: runtime compilation and precompilation. Runtime compilation compiles JSP pages when a client first requests a web application. However, for medium- to large-scale applications involving a large number of JSP pages, this compilation method results in a significant amount of time being wasted on the initial request, mainly on generating Java files and compiling them into class files. Precompilation can address this time-consuming initial request issue by compiling all JSP pages of a web application at once when the web application starts. Apache Tomcat provides the org.apache.jasper.Jsp component for implementing JSP file precompilation.
[0005] However, in Spring Boot applications, precompilation is extremely difficult to implement, mainly due to the following reasons:
[0006] One is that the org.apache.jasper.Jsp component of Spring Boot's built-in Tomcat cannot fully execute the compilation chain, which is manifested as being able to only complete the JSP to Java conversion stage, while the key Java to Class compilation link is delayed until the first request for the JSP page occurs, resulting in incomplete precompilation.
[0007] The second is that the Spring Boot project structure lacks fixed storage for compiled Class files, which causes compilation to occur every time a JSP page is requested. This leads to repeated compilation of the same JSP page, which not only causes unnecessary performance loss, but also significantly reduces the speed at which Spring Boot applications access JSP pages. According to tests, the average time taken for the first JSP access under the traditional Spring Boot solution is 1200ms±150ms, of which the dynamic compilation phase accounts for more than 65%.
[0008] Third, if a traditional external Tomcat is introduced to perform precompilation, since the external Tomcat precompilation relies on the WAR package, and the Spring Boot application is packaged as an executable JAR package by default, the external Tomcat precompiled file package cannot be directly identified. This brings about additional operations such as modifying the packaging method, which also increases additional maintenance costs.
[0009] Therefore, in order to better apply it to medium and large-scale existing application scenarios, it is particularly critical to solve the technical bottleneck of JSP precompilation in Spring Boot application scenarios and improve the loading speed of JSP pages in Spring Boot applications. Summary of the Invention
[0010] This method reconstructs the JSP compilation process of the Spring Boot application, completes the complete compilation process from the JSP page to the Java Servlet class bytecode file during the application construction phase, and generates a Class file that is exactly the same as the runtime compilation. When the Spring Boot application starts, the precompiled result is automatically loaded through the built-in Tomcat registrar. According to the mapping relationship between the JSP path registered in the built-in Tomcat registrar and the corresponding Java Servlet class, the built-in Tomcat can directly call the precompiled bytecode file when processing user requests. It is suitable for upgrading existing systems that use the Spring Boot framework and need to be compatible with traditional JSP pages. The present invention does not rely on an external Servlet container. While fully complying with the native architecture of Spring Boot, it completely eliminates the compilation overhead during the first access and ensures the precompiled results and runtime compilation. At the same time, through precompilation during the construction period, JSP syntax error detection can be advanced to the development stage, effectively reducing the risk of runtime exceptions in the production environment.
[0011] The technical solution of the present invention is as follows: a method for optimizing the first access speed of JSP pages in Spring Boot, specifically comprising the following steps:
[0012] Step 1: Precompile JSP pages in the build phase, compile them into Java Servlet class source code Java files and corresponding Java Servlet class bytecode Class files at one time, and save the mapping relationship between the Class files and JSPs. Specifically, the org.apache.jasper.JspC class is extended to generate a custom JspCompiler class, and a one-time compilation is performed by modifying the JSP configuration parameters; the mapping relationship between JSP pages and Class files is recorded, and each mapping relationship is stored in the precompilation description file jspc-web.xml in the form of a key-value pair, where the key is the request path of the JSP page and the value is the corresponding Java Servlet class name, and the class name points to the Class file;
[0013] Step 2: Remove the Java files generated after precompilation, and package other precompiled files into a Jar package. Specifically, during the Spring Boot project packaging phase, package the Class files in step 1 and the file that saves the mapping relationship into the Jar package of the Spring Boot project;
[0014] Step 3: Configure Spring Boot's embedded Tomcat container to read the files in the Jar package. Specifically, when the Spring Boot application starts, the embedded Tomcat container reads the storage path of the JSP compiled file, searches for the JSP compiled file in the Jar package, and performs the registration in step 4.
[0015] Step 4: Traverse the mapping relationship to obtain a Java Servlet class name, and register the class name in the embedded Tomcat container; according to the registered Java Servlet class name, sequentially obtain the corresponding request path from the mapping relationship, and add the request to the Java Servlet class name in the embedded Tomcat container;
[0016] Step 5: When a user requests to access the JSP page of the Spring Boot application for the first time, the Spring Boot application server searches for the Java Servlet class name corresponding to the request path in the embedded Tomcat container from the mapping relationship registered in step 4 according to the request path of the JSP page, further obtains the Class file pointed to by the Java Servlet class name, and sends it to the server for execution.
[0017] In step 1, embedding the Maven plug-in into the precompiled JSP page specifically includes:
[0018] Step 1-1: Filter and modify JSP configuration parameters: In the custom JspCompiler class inherited from the org.apache.jasper.JspC class, configure the same JSP configuration parameters as the Spring Boot application, including the trimSpaces parameter, jspConfig parameter, and mappedFile parameter; the JSP configuration parameters of the Spring Boot application are read from the configuration file of the SpringBoot project; the trimSpaces parameter is configured as single, the jspConfig parameter points to
[0019] ${basedir} / src / main / webapp / WEB-INF / jsp-config.xml, the mappedFile parameter is configured as true;
[0020] Step 1-2: Call the Ant task through the build tool plug-in to implement the compilation process, embed the Ant script in pom.xml, define the custom JspCompiler class in step 1-1 as an Ant task, and configure the Ant task parameters; when executing the Ant task, call the custom JspCompiler class to perform JSP file compilation, and save the mapping relationship in the jspc-web.xml file; the jspc-web.xml file is a newly created configuration file and is saved on the Spring Boot server.
[0021] In steps 1-2, the Ant task parameters are configured using <taskdef>The element defines the compilation task. The attributes of the task include the task name, the execution class classname, and the classpath classpath. The classname parameter is configured as the new subclass in step 1-1, and the classpath parameter is configured as the classpath maven.compile.classpath automatically generated by Maven during runtime. <artifactid>Information, download all dependencies to the class path;
[0022] In steps 1-2, the custom JspCompiler class executes the compilation process specifically by configuring the uriroot, outputDir, webXmlFragment, and compile parameters of org.apache.jasper.JspC, wherein the uriroot parameter value is set to the file storage address of the precompiled JSP page; the outputDir parameter value is set to the storage address of the Java file and the Class file; the webXmlFragment parameter value is set to the storage address of the jspc-web.xml file; and the compile parameter value is set to true to forcibly trigger the complete compilation process from JSP to Servlet class, and control the precompilation to execute the complete JSP compilation, which is specifically manifested in obtaining the Java file and Class file at one time.
[0023] In step 2, specifically including: adding the webXmlFragment parameter and the storage address specified by the outputDir parameter in steps 1-2 to the Spring Boot packaged file; and before packaging, removing the Java file from the storage address specified by the outputDir parameter; the storage address specified by the outputDir parameter is
[0024] ${project.build.directory} / generated-sources / jsp.
[0025] In step 3, the configuration specifically includes: configuring the Servlet mapping of the embedded Tomcat container by implementing the onStartup method of the ServletContextInitializer interface, and declaring the Bean through the Spring Bean declaration mechanism; the method includes two parameters, one of which is a ServletContext object. The code defining the registration mapping relationship in step 4 in the present invention is the ServletContext object; the other parameter is the file storage address of the JSP page.
[0026] In said step 4, it specifically includes:
[0027] Step 4-1: Configure the WebXmlParser parser to parse and read the Class files and mapping relationships in the Jar package, save them as WebXml objects, call the getServlets method of the WebXml object, and obtain the JavaServlet class name from the mapping relationship; the WebXmlParser parser loads the jspc-web.xml file from the META-INF directory of the Jar package through the ClassLoader;
[0028] Step 4-2: Call the addServlet method of the ServletContext interface to register each of the obtained JavaServlet class names into the embedded Tomcat container;
[0029] Step 4-3: Call the getServletRegistration method of the ServletContext interface to query the Java Servlet class name in the embedded Tomcat container; call the addMapping method of the ServletRegistration interface to add a request path for the Java Servlet name; the URL path is consistent with the request path of the JSP page.
[0030] The beneficial effects of the present invention are:
[0031] When processing Spring Boot application JSP compilation, the present invention does not introduce any external Java Servlet class server. While retaining the original compilation performance of the Spring Boot application, it removes all unnecessary compilation processes in the first request access, and implements pre-compilation of Class files with the same content as the JSP compiled by Spring Boot's built-in Tomcat, which facilitates earlier discovery of JSP page errors in the production environment and reduces configuration conflicts caused by inconsistencies.
[0032] The present invention does not rely on an external Servlet container. In full compliance with the Spring Boot native architecture, it completely eliminates the compilation overhead during the first access, ensuring the pre-compilation results and runtime compilation. At the same time, through pre-compilation during the build period, JSP syntax error detection can be advanced to the development stage, effectively reducing the risk of runtime exceptions in the production environment. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 This is a flow chart of a method for optimizing the first access speed of a Spring Boot application JSP page in an embodiment of the present invention;
[0034] Figure 2 This is a flow chart of registering mapping relationships when a Spring Boot application is started in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to make the objectives, technical solutions and advantages of the present invention more clear, the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0036] The technical solution of the present invention effectively solves the technical bottleneck of JSP precompilation under the Spring Boot architecture, such as Figure 1 This is a flow chart of a method for optimizing the first access speed of a Spring Boot application JSP page in an embodiment of the present invention, specifically including:
[0037] Step 101: Precompile JSP pages during the construction phase, compile and generate Java (source code) files and Class files at one time, and save the mapping relationship between Class files and JSP, specifically including: during the project construction phase, generate a custom JspCompiler class by extending the org.apache.jasper.JspC class, optimize the org.apache.jasper.JspC class of the Apache Tomcat server, precompile all JSP pages of the Spring Boot application, obtain and save the mapping relationship between the JSP page and the Java Servlet class bytecode Class file, each mapping relationship exists in the form of a key-value pair, where the key is the URL path (request path) of the JSP page, and the value is the corresponding Java Servlet class name, and the class name points to the Class file. Step 101 in the embodiment of the present invention solves the problem of incomplete compilation of the built-in embedded Tomcat in the Spring Boot application.
[0038] In step 101, the Maven plug-in is embedded in the process of precompiling the JSP page. Step 101 includes:
[0039] Step 101-1: Filter and modify JSP configuration parameters: In the custom JspCompiler class inherited from org.apache.jasper.JspC, configure the same JSP configuration parameters as the Spring Boot application, including the trimSpaces parameter, jspConfig parameter, and mappedFile parameter. The JSP configuration parameters of the Spring Boot application are obtained from the configuration file of the SpringBoot project, which can be the application.properties file or the application.yml file;
[0040] In this embodiment of the present invention, the org.apache.jasper.JspC class is a core class of the Apache Tomcat server, responsible for compiling and executing JSP files. However, to simplify and reduce application size, Spring Boot's embedded Tomcat does not include all of the Apache Tomcat server's features, particularly lacking direct support for JSP precompilation. Therefore, filtering and modifying specific JSP configuration parameters in the org.apache.jasper.JspC class can effectively improve Spring Boot applications' support for JSP precompilation.
[0041] In an embodiment of the present invention, considering that the org.apache.jasper.JspC class has more than 30 parameters, after technical personnel explored and tested the functions of each parameter, the parameter screening process, by comparing the differences in the compiled output of the 30 JspC parameters, ultimately determined to filter and configure the trimSpaces=single, jspConfig=${basedir} / src / main / webapp / WEB-INF / jsp-config.xml, and mappedFile=ture parameters from the Spring Boot project configuration file. These three parameters work together to help resolve the problem of inconsistent Class files caused by different compilation methods and environments. This allows pre-compiled and built-in embedded Tomcat to compile JSPs to obtain identical Class files, facilitating earlier detection of JSP page errors in production environments and reducing configuration conflicts caused by inconsistencies. The configuration values of the trimSpaces, jspConfig, and mappedFile parameters are strictly consistent with the Spring Boot runtime environment to ensure binary consistency between the pre-compiled .class files and the dynamically compiled results of the embedded Tomcat.
[0042] Step 101-2: Use the maven-antrun-plugin to embed the Ant script in pom.xml, define the custom JspCompiler class in step 1-1 as an Ant task, and configure the Ant task parameters; when executing the Ant task, call the custom JspCompiler class to compile the JSP file and save the mapping relationship in the jspc-web.xml file; since there is no web.xml configuration file in Spring Boot, create a new jspc-web.xml file and configure it on the Spring Boot server.
[0043] In step 101-2, the configuration of Ant task parameters is specifically to use <taskdef>The element defines the compilation task. The attributes of the task include the task name, the execution class classname, and the classpath parameter. The classname parameter is configured as the new subclass in step 101-1, and the classpath parameter is configured as the classpath maven.compile.classpath automatically generated by Maven during runtime. <artifactid>Information, download all dependencies to the class path.
[0044] In step 101-2, the custom JspCompiler class performs compilation by configuring the uriroot, outputDir, webXmlFragment, and compile parameters of org.apache.jasper.JspC, wherein the uriroot parameter value is set to the file storage address of the JSP page, such as
[0045] ${basedir} / src / main / webapp; set the outputDir parameter value to the storage address of the Java file and the Class file; set the webXmlFragment parameter value to the storage address of the jspc-web.xml file; set the compile parameter value to true to control the precompilation to perform a complete JSP compilation. Specifically, it obtains the Java file and the Class file at one time and forces the generation of executable bytecode to avoid triggering JSP compilation again when the Spring Boot built-in embedded Tomcat is running.
[0046] In step 101-2, add dependency configuration to the pom.xml file, specifically adding the additional JSP support dependency tomcat-embed-jasper. This is because the new JspC class inherits from the org.apache.jasper.JspC class, so configuring the Tomcat dependency is required. Maven automatically downloads the required dependency JAR files from Maven Central, using the pom.xml file for the dependency declaration.
[0047] Step 102: In the project packaging stage, remove the Java source code files generated after precompilation, and package other precompiled files into a Jar package, including bytecode files and precompiled description files. Specifically, in the Spring Boot project packaging stage, the Class file in step 1 and the file that saves the mapping relationship are packaged together into the Jar package of the Spring Boot project.
[0048] In the packaging in step 102, specifically, the webXmlFragment parameter and the storage address specified by the outputDir parameter in step 101-2 are added to the Spring Boot package file; before packaging, the Java file is removed from the storage address specified by the outputDir parameter;
[0049] The Spring Boot project packaging refers to the process of converting the Spring Boot application into a deployable format. It supports two packaging methods: Jar package and War package. To simplify the deployment process, it is packaged into a Jar package by default. The Jar package has Spring Boot's built-in embedded Tomcat server. When the Spring Boot application supports JSP, the JSP file needs to be compiled into a Java Servlet class. This process occurs when the Tomcat container is running. However, because the resources in the Jar package are compressed and stored, the class loader of the built-in embedded Tomcat container cannot directly compile the JSP file from the Jar package. As a result, each time a JSP page of the Spring Boot application is requested, it needs to be recompiled, which increases the waste of compilation resources. This discovery completes all compilations before the Spring Boot application is started through precompilation in step 1, and generates a Java Servlet class bytecode Class file. This not only overcomes the limitations of Spring Boot's support for JSP compilation, but also does not require the introduction of an external Tomcat container, ensuring a simplified deployment process.
[0050] Step 103: Configure Spring Boot's built-in embedded Tomcat container to read files in the Jar package: Specifically, when the Spring Boot application is started, control the built-in embedded Tomcat container to search the JSP compiled file from the Jar package through the storage path of the JSP compiled file, and execute step 104 to register the Servlet;
[0051] The configuration in step 103 takes effect when the Spring Boot application is started. The configuration specifically includes:
[0052] The method for starting compilation is defined as the onStartup method of the ServletContextInitializer interface and annotated with @Bean through the Spring Bean declaration mechanism; the method includes two parameters, one of which is the ServletContext object. In the embodiment of the present invention, the code defining the registration mapping relationship in step 104 is the ServletContext object; the other parameter is the storage address of the jspc-web.xml file.
[0053] Step 103 starts the compilation configuration by utilizing Spring Boot's automatic configuration mechanism. When the Spring Boot application starts, it can search for methods annotated with @Bean, automatically detect and call all methods that implement the ServletContextInitializer interface, and then call the method that starts the compilation to execute the subsequent registration mapping process.
[0054] Step 104: Dynamic registration phase, parse the pre-compiled description file to generate a WebXml object, traverse the Servlet definition of the object, batch register Servlet classes through the addServlet method of the ServletContext interface, and bypass Tomcat's default JspServlet matching logic through the addMapping method of the ServletRegistration interface to directly establish a mapping relationship between the request path and the pre-compiled Servlet, so that the peak CPU resource usage of the server is reduced by more than 60%, and the mapping relationship is registered in the built-in embedded Tomcat server of the Spring Boot application. Figure 2 This is a flow chart of registering a mapping relationship when a Spring Boot application is started in an embodiment of the present invention, specifically including:
[0055] Step 104-1: Parse and read the Class files and mapping relationships in the Jar package; specifically, configure the WebXmlParser parser to parse the contents of the jspc-web.xml file in the Jar package, save the read mapping relationship as a WebXml object, and provide a data source for subsequent Servlet registration;
[0056] The WebXmlParser is a tool class provided by Apache Tomcat specifically for parsing the web.xml configuration file. It is one of the core modules of Tomcat and specifically processes the deployment descriptor file web.xml of the Servlet specification.
[0057] Step 104-2: registering the Java Servlet class in the built-in embedded Tomcat container, including: traversing the mapping relationship to obtain all Java Servlet class names, and registering and writing the Java Servlet class names in the built-in embedded Tomcat container; the traversal operation in step 104-2 is performed when the Spring Boot application is started;
[0058] In step 104 - 2 , the addServlet method of the ServletContext interface is called to register and write each Java Servlet class name.
[0059] Step 104-3: Register the mapping relationship in the built-in embedded Tomcat container according to the Java Servlet class: traverse all mapping relationships, each mapping relationship exists in the form of a key-value pair, where the key is the URL path of the JSP page and the value is the corresponding Java Servlet class name; obtain the Java Servlet class name registered in step 104-2 in turn, and search the corresponding URL path from the mapping relationship according to the Java Servlet class name; in the built-in embedded Tomcat container, add the URL path to the Java Servlet class name.
[0060] In step 104-3, the getServletRegistration method of the ServletContext interface is called to query the Java Servlet class name in the embedded Tomcat container. The addMapping method of the ServletRegistration interface is called to add the URL path to the Java Servlet name. When calling the addMapping method, the URL path matching priority is set to the highest level (ORDER=1), overriding the default JspServlet routing rules.
[0061] Step 105: When a JSP page is first requested, the server finds the class file based on the registered mapping and executes it. Specifically, when a user requests a JSP page from a Spring Boot application, the Spring Boot application server searches the embedded Tomcat container for the corresponding Java Servlet class name based on the page URL and the mapping registered in Step 104. It then retrieves the class file pointed to by the Java Servlet class name and executes it on the server. Directly invoking the precompiled Servlet class bytecode file for response reduces the average response time for first-time access to ≤ 350ms.
[0062] Compared with the traditional solution without optimization, the practical data is as follows:
[0063]
[0064] When processing Spring Boot application JSP compilation, the present invention does not introduce any external Java Servlet class server. While retaining the original compilation performance of the Spring Boot application, it removes all unnecessary compilation processes in the first request access, and implements pre-compilation of Class files with the same content as the JSP compiled by Spring Boot's built-in Tomcat, which facilitates earlier discovery of JSP page errors in the production environment and reduces configuration conflicts caused by inconsistencies.
[0065] The present invention does not rely on an external Servlet container. In full compliance with the Spring Boot native architecture, it completely eliminates the compilation overhead during the first access, ensuring the pre-compilation results and runtime compilation. At the same time, through pre-compilation during the build period, JSP syntax error detection can be advanced to the development stage, effectively reducing the risk of runtime exceptions in the production environment.
[0066] The present invention may also have many other implementation methods. The above embodiments do not limit the present invention in any way. Without departing from the spirit and essence of the present invention, those skilled in the art may make various corresponding changes and modifications based on the present invention. Any other improvements and applications made to the above embodiments in an equivalent transformation manner shall fall within the scope of protection of the claims attached to the present invention.< / artifactid> < / taskdef> < / artifactid> < / taskdef>
Claims
1. A method for optimizing the first access speed of JSP pages in Spring Boot, characterized in that: include: Step 1: Precompile JSP pages in the build phase, compile them into Java Servlet class source code Java files and corresponding Java Servlet class bytecode Class files at one time, and save the mapping relationship between the Class files and JSPs. Specifically, the org.apache.jasper.JspC class is extended to generate a custom JspCompiler class, and a one-time compilation is performed by modifying the JSP configuration parameters; the mapping relationship between JSP pages and Class files is recorded, and each mapping relationship is stored in the precompilation description file jspc-web.xml in the form of a key-value pair, where the key is the request path of the JSP page and the value is the corresponding Java Servlet class name, and the class name points to the Class file; Step 2: Remove the Java files generated after precompilation, and package other precompiled files into a Jar package. Specifically, during the Spring Boot project packaging phase, package the Class files in step 1 and the file that saves the mapping relationship into the Jar package of the Spring Boot project; Step 3: Configure Spring Boot's embedded Tomcat container to read the files in the Jar package. Specifically, when the Spring Boot application starts, the embedded Tomcat container reads the storage path of the JSP compiled file, searches for the JSP compiled file in the Jar package, and performs the registration in step 4. Step 4: Traverse the mapping relationship to obtain a Java Servlet class name, and register the class name in the embedded Tomcat container; according to the registered Java Servlet class name, sequentially obtain the corresponding request path from the mapping relationship, and add the request to the Java Servlet class name in the embedded Tomcat container; Step 5: When a user requests to access the JSP page of the Spring Boot application for the first time, the Spring Boot application server searches for the Java Servlet class name corresponding to the request path in the embedded Tomcat container from the mapping relationship registered in step 4 according to the request path of the JSP page, further obtains the Class file pointed to by the Java Servlet class name, and sends it to the server for execution.
2. A method for optimizing the first access speed of a JSP page in Spring Boot according to claim 1, characterized in that: In step 1, embedding the Maven plug-in into the precompiled JSP page specifically includes: Step 1-1: Filter and modify JSP configuration parameters: In the custom JspCompiler class inherited from the org.apache.jasper.JspC class, configure the same JSP configuration parameters as the Spring Boot application, including the trimSpaces parameter, the jspConfig parameter, and the mappedFile parameter. The JSP configuration parameters of the Spring Boot application are read from the Spring Boot project configuration file. The trimSpaces parameter is configured as single, the jspConfig parameter points to ${basedir} / src / main / webapp / WEB-INF / jsp-config.xml, and the mappedFile parameter is configured as true. Step 1-2: Call the Ant task through the build tool plug-in to implement the compilation process, embed the Ant script in pom.xml, define the custom JspCompiler class in step 1-1 as an Ant task, and configure the Ant task parameters; when executing the Ant task, call the custom JspCompiler class to perform JSP file compilation, and save the mapping relationship in the jspc-web.xml file; the jspc-web.xml file is a newly created configuration file and is saved on the Spring Boot server.
3. A method for optimizing the first access speed of JSP pages in Spring Boot according to claim 2, characterized in that: In steps 1-2, the Ant task parameters are configured using <taskdef>The element defines the compilation task. The attributes of the task include the task name, the execution class classname, and the classpath classpath. The classname parameter is configured as the new subclass in step 1-1, and the classpath parameter is configured as the classpath maven.compile.classpath automatically generated by Maven during runtime. <artifactid> Information, download all dependencies to the class path;< / artifactid> < / taskdef> In steps 1-2, the custom JspCompiler class executes the compilation process specifically by configuring the uriroot, outputDir, webXmlFragment, and compile parameters of org.apache.jasper.JspC, wherein the uriroot parameter value is set to the file storage address of the precompiled JSP page; the outputDir parameter value is set to the storage address of the Java file and the Class file; the webXmlFragment parameter value is set to the storage address of the jspc-web.xml file; and the compile parameter value is set to true to forcibly trigger the complete compilation process from JSP to Servlet class, and control the precompilation to execute the complete JSP compilation, which is specifically manifested in obtaining the Java file and Class file at one time.
4. A method for optimizing the first access speed of a JSP page in Spring Boot according to claim 3, characterized in that: In step 2, specifically including: adding the webXmlFragment parameter and the storage address specified by the outputDir parameter in steps 1-2 to the Spring Boot packaged file; and before packaging, removing the Java file from the storage address specified by the outputDir parameter; the storage address specified by the outputDir parameter is ${project.build.directory} / generated-sources / jsp.
5. A method for optimizing the first access speed of a JSP page in Spring Boot according to claim 4, characterized in that: In step 3, the configuration specifically includes: configuring the Servlet mapping of the embedded Tomcat container by implementing the onStartup method of the ServletContextInitializer interface, and declaring the Bean through the Spring Bean declaration mechanism; the method includes two parameters, one of which is a ServletContext object. The code defining the registration mapping relationship in step 4 in the present invention is the ServletContext object; the other parameter is the file storage address of the JSP page.
6. A method for optimizing the first access speed of a JSP page in Spring Boot according to claim 5, characterized in that: In said step 4, it specifically includes: Step 4-1: Configure the WebXmlParser parser to parse and read the Class files and mapping relationships in the Jar package, save them as WebXml objects, call the getServlets method of the WebXml object, and obtain the JavaServlet class name from the mapping relationship; the WebXmlParser parser loads the jspc-web.xml file from the META-INF directory of the Jar package through the ClassLoader; Step 4-2: Call the addServlet method of the ServletContext interface to register each of the obtained JavaServlet class names into the embedded Tomcat container; Step 4-3: Call the getServletRegistration method of the ServletContext interface to query the Java Servlet class name in the embedded Tomcat container; call the addMapping method of the ServletRegistration interface to add a request path for the Java Servlet name; the URL path is consistent with the request path of the JSP page.