If you're intending to hold a list of records in the attribute rowsFromDb
, then you should populate this in your controller and set the list in the model. Then in data.jsp
you can iterate this list using the <c:forEach>
tag. For example (a madeup example to illustrate the point):
Controller
@RequestMapping("/listRows")
public ModelAndView listRows() {
List<Row> rows = myRepository.getAllRows(); // Hide the DB query code behind a repository
ModelAndView modelAndView = new ModelAndView("/");
modelAndView.addObject("rowsFromDb", rows); // Set the data in the model
return modelAndView;
}
data.jsp
<c:forEach items="${rowsFromDb}" var="row">
<c:out value="${row.someProperty}"/>
<c:forEach>
You should avoid doing any database query directly in the JSP itself (and avoid any Java in the JSP where possible). The JSP should just deal with rendering the data it is given by the controller.