Creating a Spring boot project using Spring Tool Suite (STS)
1. Project Structure:
first-spring-boot/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/demo/
│ │ │ └── [Link]
│ │ ├── resources/
│ │ │ ├── [Link]
│ │ └── webapp/
│ │ └── WEB-INF/
│ │ └── views/
│ │ └── [Link]
├── [Link]
2. Create a Project:
2.1 Click on Spring Starte Project
2.2 Provide below details.
Name: first-spring-boot
Type: Maven
Packaging: Jar
Java Version: 17
Language: Java
Group: [Link]
Artifact: first-spring-boot
Package: [Link]
2.3 Search for Spring web and Select Spring Web, Click next and Finish. It will create a new
project in Package Explorer.
2.4 Confirm below folder structure is created.
3. Modify the [Link] file, add the dependencies in the file and save it.
<!-- JSP Support -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>[Link]-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>[Link]-api</artifactId>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>[Link]</artifactId>
</dependency>
4. Check the Main Spring Boot Application is correct.
5. Create a controller folder inside [Link] package
6. Create new controller class inside [Link] package with below code.
package [Link];
import [Link];
import [Link];
@Controller
public class HomeController {
@GetMapping("/")
public String home() {
return "home"; // JSP file name ([Link])
}
}
7. Add JSP files folder path configurations in [Link].
[Link]=/WEB-INF/views/
[Link]=.jsp
8. Create Folder path src/main/webapp/WEB-INF/views. Add [Link] file and copy below
code.
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h2>Hello, Spring Boot with JSP!</h2>
</body>
</html>
9. Run the Spring boot project.