Harshit
Harshit

Reputation: 5157

Spring get session class object

I am trying to get the class object from session attribute. Here is the code

IndexController.java

User user = new User();
user.setEmail("EMAIL");
user.setName("name");
session.setAttribute("session_user", user);

index.jsp

<c:choose>
     <c:when test="${session_user != null}"
Hello <c:out value="${session_user[user.getName()]}">
     </c:when>
</c:choose>

But it is not printing anything?

Upvotes: 0

Views: 93

Answers (1)

Faraz
Faraz

Reputation: 6265

Replace that Hello line in your index.jsp with:

Hello <c:out value="${session_user.name}">

Those EL expressions don't understand getter/setters you just type the property name to get the value out of it. And what is [...] for? You are not going over List.

Upvotes: 2

Related Questions