Spring Boot Hello World – JSP tutorial

Tutorial describing how to create the simple Hello World application using Spring Boot and JSP.

Technologies used:

  1. Spring Boot 2.1.7.RELEASE
  2. JDK 1.8
  3. Maven 3
  4. JSP

Project setup

Project dependencies managed by the Maven’s pom.xml configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">







The explanation of the above dependencies:

  • spring-boot-starter-web – packages all the necessary dependencies together with the auto configuration for running simple web application
  • spring-boot-starter-tomcat – provides the embedded tomcat application server
  • tomcat-embed-jasper – enables support for JSP
  • spring-boot-maven-plugin – plugin prividing commands to work with a Spring Boot application (we will be usine the spring-boot:run command)

Application Initializer

The standard spring boot application initializer, which our application need to provide:

public class Application extends SpringBootServletInitializer {

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);

public static void main(String[] args) {
SpringApplication.run(Application.class, args);


The controller containing rest services:

public class HelloWorldController {

private static final String message = "Hello World";

@GetMapping(value = "/")
public String hello(Map<String, Object> model) {
model.put("message", message);
return "hello";

The controller has only one endpoint available at the root address (/ – in our example it is resolved to the localhost:8080) . The method passes the message parameter to the hello view.


<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html lang="en">
    <meta charset="UTF-8">

The view contains a simple html page, that shows passed parameter.


The configuration in application.properties file contains information how to resolve JSP files.

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp


The project can be started by the running the following command:

mvn clean spring-boot:run

The command deploys the apllication on the embedded tomcat server.

By visiting the localhost:8080 url, we should see the page containg the Hello World message.

The example code you can download from here

Leave a Reply

Your email address will not be published. Required fields are marked *