This tutorial walks you through the steps of creating a Hello World web app example with Spring Boot and JSP

Spring Boot is a popular Java-based framework used to build production-grade web applications and services. You can find more Spring Boot tutorials here

JSP is a Java-based server-side template engine

What you'll build

What you'll need

  • JDK 8+ or OpenJDK 8+
  • Maven 3+

Init project structure

You can create and init a new Spring Boot project by using Spring CLI or Spring Initializr. Learn more about using these tools here

The final project structure as below

├── src
│   └── main
│       ├── java
│       │   └── com
│       │       └── hellokoding
│       │           └── springboot
│       │               └── view
│       │                   ├── Application.java
│       │                   └── HelloController.java
│       ├── resources
│       │   ├── static
│       │   │   ├── css
│       │   │   │   └── main.css
│       │   │   └── js
│       │   │       └── main.js
│       │   └── application.properties
│       └── webapp
│           └── WEB-INF
│               └── jsp
│                   └── hello.jsp
└── pom.xml

Project dependencies

Add spring-boot-starter-web and tomcat-embed-jasper into your project as a dependency on pom.xml or build.gradle file. The library versions can be omitted as it is resolved by the parent pom provided by Spring Boot

<dependencies>  
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
</dependencies>  

You can find the full pom.xml file as below


Create Controller


@Controller indicates the annotated class is a web controller

@GetMapping maps HTTP GET request for "/" (home page) and "/hello" to the hello method

@RequestParam binds method parameter name to request query string parameter (value="name",...)

Model is an object sharing data between handler and view template

The view template name is defined by the return statement of the handler and the spring.mvc.view.suffix config property which defined in the below application.properties file. So in this hello handler method, the return view is hello.jsp

View Template


Static files



Application Configurations



Run and Test

You can run the application by typing the following command on the terminal console at the project root directory

$ mvn clean spring-boot:run

You would see this text in the console

o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''  

Access to http://localhost:8080 on your web browser, the following response is expected

Hello, World!

Source code

https://github.com/hellokoding/hellokoding-courses/tree/master/springboot-examples/springboot-jsp-helloworld