0

The problem: Unsure on how I can access the HashMap that is located in my java class in my JSP page and how I can display the key and/or value of that HashMap to my JSP.

Below is where my HashMap is located inside PseudoDB.java: `

public class PseudoDB {
    HashMap<String, String> LoginUser = new HashMap<String, String>();
    HashMap<String, String> UserRole = new HashMap<String, String>();
    HashMap<String, Integer> Subjects = new HashMap<String, Integer>();

    //Users Functions
    public void AddUser (String username, String password) {
        String TempUsername = username;
        String TempPassword = password;
        LoginUser.put(TempUsername, TempPassword);
    }
    
    public void EditUser (String username, String password) {
        String TempUsername = username;
        String TempPassword = password;
        LoginUser.replace(TempUsername, TempPassword);
    }
    
    public void RemoveUser (String username) {
        String TempUsername = username;
        LoginUser.remove(TempUsername);
        UserRole.remove(TempUsername);
    }

    public Boolean UserExists (String username) {
        Boolean Check = false;
        Check = LoginUser.containsKey(username);
        return Check;
    }
    
    //Roles Functions
    public void AddRole (String username, String role) {
        String TempUsername = username;
        String TempRole = role;
        LoginUser.put(TempUsername, TempRole);
    }

    //Subjects Functions
    public void AddSubject (String subjectname, Integer weight) {
        String TempName = subjectname;
        Integer TempWeight = weight;
        Subjects.put(TempName, TempWeight);
    }
    
    public void EditSubject (String subjectname, Integer weight) {
        String TempName = subjectname;
        Integer TempWeight = weight;
        Subjects.replace(TempName, TempWeight);
    }
    
    public void RemoveSubject (String subjectname) {
        String TempName = subjectname;
        Subjects.remove(TempName);
    }
    
    public Boolean SubjectExists (String username) {
        Boolean Check = false;
        Check = Subjects.containsKey(username);
        return Check;
    }
    
    //Login Functions
    public String Check(String username) {
        String TempName = LoginUser.get(username);
        return TempName;
    }
    
    public String GetRole(String username) {
        String TempRole = UserRole.get(username);
        return TempRole;
    }
}

` enter image description here - this is my JSP page where I want to display the key/values

I've come to a stop and looked on how I can access the HashMap and display the key/value of it to my jsp to no avail. What I expect to see in my JSP page is that, the HashMap Subjects will be displayed in my JSP page.

ッSparc
  • 21
  • 2
  • 1
    Does this answer your question? [How to loop through a HashMap in JSP?](https://stackoverflow.com/questions/1835683/how-to-loop-through-a-hashmap-in-jsp) – FredvN Nov 29 '22 at 09:48
  • @FredvN quite near to my question, but I'm not that knowledgeable in JSTL – ッSparc Nov 29 '22 at 10:23
  • @FredvN do you know other way to do it without JSTL? – ッSparc Nov 29 '22 at 10:38
  • you can also use scriptlets, see https://stackoverflow.com/questions/16463566/accessing-a-java-map-inside-a-scriptlet – FredvN Nov 29 '22 at 10:49

0 Answers0