I am using hibernate to get the subjects associated with a particular user. In mainPage, I want to see firstName and LastName (this works) of the user and allowed subjects. But, for some reason, I am not able to successfully iterate over the list of subjects put in mainPage.
In my Spring controller I have a method, which looks like this:
@RequestMapping(value = "/signin", method = RequestMethod.POST)
public String SignIn(@ModelAttribute("user") User user, ModelMap modelMap){
String username = user.getUsername();
String password = user.getPassword();
User user1 = userService.getUser(username, password);
if(user1 != null){
List<Subject> subjectList = userService.getUserSubjects(user1.getId());
modelMap.addAttribute("subjects", subjectList);
modelMap.addAttribute("user", user1);
return "mainPage";
}
modelMap.addAttribute("ShowNotAuthenticated", true);
return "authentication";
}
mainPage.jsp looks like this:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h2>Current user: ${user.firstName} ${user.lastName}</h2> //this works
<br>
<h3>Allowed subjects:</h3>
<table>
<tr>
<td>
Subject Name
</td>
</tr>
<c:forEach items="${subjects}" var="x"> //doesn't work
<tr>
<td>
${x.name}
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
This is SignIn method during debug:
These are pictures in mainPage.jsp:
Mykhailo Moskura's suggestion doesn't work too:



