You are currently viewing Spring Boot Masterclass – Display the list of expense in JSP 08

Spring Boot Masterclass – Display the list of expense in JSP 08

Hello, in this post we will display the list of expenses in the JSP view template. Let’s begin. First, we need to add the dependency for the JSTL tag library in pom.xml



Next, add a list of expenses to the model and view object in order to access it in JSP view template

public ModelAndView home() {
	ModelAndView mav = new ModelAndView("home");
	mav.addObject("message", "List of expenses");
	List<Expense> expenses = expenseService.findAll();
	mav.addObject("expenses", expenses);
	return mav;

Next, add a reference to the JSTL tag library inside the view template and loop through the list of expenses using the JSTL forEach tag.


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

<%@ taglib prefix="c" uri="" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<h1>Expense Tracker</h1>
	<c:forEach var="expense" items="${expenses}">

That’s it for this post. This ends the feature 1 for Expense Tracker. I will see you in the next feature. Let me know in the comment section if you have any queries anything on this.


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.

Leave a Reply