Issue
I am new to spring boot and trying to create a simple ToDo Application using spring boot and JSP. I am trying to show the list of todo's in my JSP but it is not reflecting. I tried all the ways whereas on putting breakpoint in IntelliJ idea, I am able to see the list of todo's in my repo.
ToDoView.jsp
<%@ include file="header.jsp"%>
<%@ include file="navigation.jsp"%>
<div class="container">
<div>
<a type="button" class="btn btn-primary btn-md" href="/add-todo">Add Todo</a>
</div>
<br>
<div class="panel panel-primary">
<div class="panel-heading">
<h3>List of TODO's</h3>
</div>
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<th width="40%">Description</th>
<th width="40%">Target Date</th>
<th width="20%"></th>
</tr>
</thead>
<tbody>
${todolist}
<c:forEach items="${todolist}" var="todo">
<tr>
<td>${todo.description}</td>
<td>${todo.getDescription()}</td> <td><fmt:formatDate value=${todo.getToDoDate()} pattern="dd/MM/yyyy" /></td>
<td><a type="button" class="btn btn-success" href="/update-todo?id=${todo.getId()}">Update</a>
<a type="button" class="btn btn-warning" href="/delete-todo?id=${todo.getId()}">Delete</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
</div>
<%@ include file="footer.jsp"%>
HomeController.java
package com.toDoApp.ToDoApp;
@Controller
public class HomeController
{
@Autowired
ToDoRepo repo;
@RequestMapping("/")
public static String home()
{
return "Home";
}
@GetMapping(path = "/list-todos", produces = {"application/json"})
public String toDoView(Model m)
{
m.addAttribute("todolist", repo.findAll());
return "ToDoView";
}
}
ToDoRepo.java
public interface ToDoRepo extends JpaRepository<ToDoList, Integer>
{
}
ToDoList.java
package com.toDoApp.ToDoApp;
import javax.persistence.*;
import java.util.Date;
@Entity
public class ToDoList
{
@Id
private int id;
private String description;
private Date toDoDate;
public ToDoList()
{
super();
}
public ToDoList(String description, Date toDoDate)
{
super();
this.description = description;
this.toDoDate = toDoDate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getToDoDate() {
return toDoDate;
}
public void setToDoDate(Date toDoDate) {
this.toDoDate = toDoDate;
}
}
I tried all other ways but didn't able to find anything. Please help me out.
Thank You
Solution
Add the jasper Dependency
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
and change the td tags like this
${todo.getDescription()}Answered By - Janil101
Answer Checked By - Mary Flores (JavaFixing Volunteer)