This article uses a simple example to demonstrate: How to build a spring boot web applicaiton with JSP.
As a relatively obsolete technology，By default, the JSP is not used as a template for web page rendering in Spring Boot 2, However, in the face of some old system upgrades written in JSP, you may also want to be able to configure support for JSP.
Next, let’s build a Spring Boot Web Application from scratch and then add support for JSPs.
For the detail of operation, we also provide a voide tutorial in youtube, you can watch it.
First, in Spring Boot Starter, fill in the basic configuration information for the project.
Depending on the objectives of the experiment, we chose to use maven as the build tool, Java as the programming language, Select the current stable version for Spring Boot, and Spring Web Starter as the support package.
To support JSP, We need to add the JSP parser in project. In this example, we choose tomcat-embed-jasper library.
Add tomcat-embed-jasper library in pom.xml file, The final pom file is as follows:
In Spring Boot Web Application, each HTTP request can be configured to respond with a corresponding method in the Controller. In this case, we built a Controller to respond to the root and ‘hello’ path.
Create a new package named controller and create a new class in the package named HelloController, as follows:
About the more information about spring mvc controller, you can refer the Offical Documentation
Create a new webapp directory in the src/main directory, and then create a WEB-INF/jsp directory in the webapp directory. Finally, create a file named hello.jsp in the jsp directory, which content as follows:
Rename the application.properties file in src/main/resources: application.yml, and add the following:
Run the Web Application
If you run it in console, you can execute:
If you use IDE tools, you can call maven in the IDE menu to run the application.
After the application is running, you can access the following URL via your browse.
You can see something like this in your browser
You can download the completed code from GitHub