0

hello I successfully get the logged in username value from servelt into JSP page as below:

Welcome:${loginedUser.userName} 

I need to use this username in If condition in JSP page to compare with another value like for example:

<%if(tc.getTEAssigned().equalsIgnoreCase(${loginedUser.userName}) %>

set Attribute:

    // Store user info in Session.
public static void storeLoginedUser(HttpSession session, UserAccount loginedUser) {
    // On the JSP can access via ${loginedUser}
    session.setAttribute("loginedUser", loginedUser);        
}

UserAccount contains those values:

   private String userName;
   private String gender;
   private String password;
   private List<String> roles;

i tried to use

 <%=session.getAttribute("loginedUser") %>

but it result is

com.jdbc.UserAccount@2990e7ee

so my question is how to use ${loginedUser.userName} value in If conditions

M.Zaky
  • 41
  • 1
  • 10
  • already data passed from Servelt to JSP and printed successfully in GUI also but now i need to use this data into JSP in if condition as this user can view this page but i need to validate if he can make any action on it or just view without taking any action – M.Zaky Sep 13 '20 at 12:09
  • then please define your question more specifically. What you have? what you want to achieve? and name the title accordingly. – Giorgi Tsiklauri Sep 13 '20 at 12:10
  • Just get that data using `request.getAttribute("something")` and then use in your `if` condition . – Swati Sep 13 '20 at 12:11
  • Giorgi: Questions updated – M.Zaky Sep 13 '20 at 12:23
  • Swati: i used <%=session.getAttribute("loginedUser") %> but it value is "com.jdbc.UserAccount@2990e7ee" noting that logiendUser contains more than value like "username, Password and roles" – M.Zaky Sep 13 '20 at 12:24
  • You can do like this `UserAccount sb=(UserAccount)request.getAttribute("loginedUser");` and then access username value using getter method i.e :`sb.getUsername()` – Swati Sep 13 '20 at 12:56

0 Answers0