You are currently viewing Spring Boot Masterclass – Configure the JSP view template 03

Spring Boot Masterclass – Configure the JSP view template 03

In this post, we will configure the JSP view template in the Spring boot application. let’s begin. First, we need to add a dependency in pom.xml in order to use the JSP as a view template in Spring boot application.

pom.xml




<dependency>
	<groupId>org.apache.tomcat.embed</groupId>
	<artifactId>tomcat-embed-jasper</artifactId>
	<scope>provided</scope>
</dependency>

Next, configure prefix and suffix in the properties file

application.properties

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp

Next, create a file home.jsp inside the src/main/webapp/WEB-INF/views/ folder

home.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	
	<h1>Expense Tracker</h1>
	<p>${message}</p>
	
</body>
</html>

Next, create a controller and handler method to serve the home page. Inside the src/main/java/in/bushansirgur/expenseyoutube/ create a package with name controller

MasterController.java

@Controller
public class MasterController {
	
	@RequestMapping("/")
	public ModelAndView home() {
		ModelAndView mav = new ModelAndView("home");
		mav.addObject("message", "List of expenses");
		return mav;
	}
	
}

That’s it for this post. Let me know in the comment section if you have any queries.

Thanks
Bushan SC

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

This Post Has 4 Comments

  1. ARAVIND KUAMR

    In My System Not Show the Home Page in Browser
    It Shows
    Whitelabel Error Page
    This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Fri Jul 24 20:03:36 IST 2020
    There was an unexpected error (type=Not Found, status=404).
    No message available
    This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Fri Jul 24 20:03:36 IST 2020
    There was an unexpected error (type=Not Found, status=404).
    No message available

    1. Bushan Sirgur

      Hello Aravind, if you don’t configure JSP properly in your application then you will face this Whitelabel error.So make sure to check the configuration inside the application properties file.

    2. Niranjan Vaddi

      I too have come across this issue but resolved it by adding below line in application.properties server.error.whitelabel.enabled=false

  2. Kunal Patil

    I am getting the same error

    Whitelabel Error Page
    This application has no explicit mapping for /error, so you are seeing this as a fallback.

    Thu Sep 10 15:09:19 IST 2020
    There was an unexpected error (type=Not Found, status=404).
    No message available

Leave a Reply to Niranjan Vaddi Cancel reply