Spring Boot MVC Example with JSP

In this tutorial, we will learn how to create a simple Spring boot + Spring MVC example with JSP.
Learn spring boot at https://www.javaguides.net/p/spring-boot-tutorial.html.
Learn JSP at https://www.javaguides.net/p/jsp-tutorial.html
Learn Spring MVC at https://www.javaguides.net/p/spring-mvc-tutorial.html 
JSP is a Java-based server-side template engine to create dynamic web pages.
When you add the spring-boot-starter-web dependency, it will by default pull all the commonly used libraries while developing Spring MVC applications, such as spring-webmvc, jackson-json, validation-api, and tomcat.
Not only does the spring-boot-starter-web add all these libraries but it also configures the commonly registered beans like DispatcherServlet, ResourceHandlers, MessageSource, etc. with sensible defaults.
Let's use Spring boot to create Spring MVC application and minimize the configuration as much as possible.

Video Tutorial

This tutorial explained in-detail in below video tutorial:

Tools and technologies used

  1. Spring boot 2+
  2. Spring MVC 5+
  3. IDE - Eclipse STS
  4. Maven 3+
  5. Embedded Tomcat server 8.5+

Development Steps

1. Create a Spring Boot Application

There are many ways to create a Spring Boot application. You can refer below articles to create a Spring Boot application.

2. Add maven dependencies

<?xml version="1.0" encoding="UTF-8"?>
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <relativePath />
        <!-- lookup parent from repository -->
    <description>Demo project for Spring Boot and JSP</description>
        <!-- JSTL for JSP -->
In order to work with JSP/JSTL, we need to add below two dependencies:
<!-- JSTL for JSP -->

3. Create Spring MVC Controller

Let's create a simple Spring MVC controller with method handler:
package net.javaguides.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

public class HelloController {

    public String hello(@RequestParam(value = "name", defaultValue = "World",
        required = true) String name, Model model) {
        model.addAttribute("name", name);
        return "hello";

4. JSP ViewResolver Configuration in application.properties file

Let's add below properties in application.properties file to configure view resolver for JSP:

5. Create JSP page

Let's create a simple JSP page under webapp/WEB-INF/jsp folder structure. If webapp folder does not exist then create webapp/WEB-INF/jsp folder structure and then create JSP pages under it.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
     <h2 align="center"> Hello ${name}!</h2>

6. Run app and demo

Let's run this spring boot application from IDE -> Right-click -> Run As -> Java Application:
package net.javaguides.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringbootJspHelloWorldExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootJspHelloWorldExampleApplication.class, args);
We added spring-boot-starter-web, which pulls spring-boot-starter-tomcat automatically. When
we run the main() method, it starts tomcat as an embedded container so that we don’t have to deploy our application on any externally installed tomcat server.


Demo of this tutorial covered in below video tutorial:
Spring Boot JSP Hello World Example Tutorial ( YouTube Video)


In this tutorial, we have learned how to create a simple Spring boot MVC hello world example with JSP.
Learn spring boot at https://www.javaguides.net/p/spring-boot-tutorial.html.
Learn JSP at https://www.javaguides.net/p/jsp-tutorial.html


  1. I agree with a lot of the points you made in this article. If you are looking for the Spring Tutorial, then visit w3spoint. I appreciate the work you have put into this and hope you continue writing on this subject.


Post a comment