I have put an object in the session:
session.setAttribute("userDTO", currentUser);
And I am trying to display it using EL. I have succeeded with scriplets (proving that the object is set in the session fine).
Code in JSP:
<body>
<% UserDTO userdto=(UserDTO)session.getAttribute("userDTO"); %>
<%=userdto.getUsername() %>
Username from session:<c:out value="${sessionScope.userDTO.username }"/>
</body>
The scriplets display the username but nothing is displayed after "Username from session:". Why?
UserDTO class:
public class UserDTO {
private int ID;
private String email;
private boolean emailConfirmed;
private String username;
private String role;
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public boolean isEmailConfirmed() {
return emailConfirmed;
}
public void setEmailConfirmed(boolean emailConfirmed) {
this.emailConfirmed = emailConfirmed;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
In your JSP you can simply do it by using the expression (its called EL - expression language) -
<body>
Username from session : ${sessionScope.currentUser}
</body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With