Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashMap problem

 
Syskata Mitev
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i use this part of code in Servlet that i wont to make check for user, password and rules and for differеnt rules to go different JSP but it's not working right.

Iterator <Map.Entry<String,String>> it = userMap.entrySet().iterator();
int id = 0;
while (it.hasNext()){
Map.Entry<String,String> temp = it.next();
if ((temp.getKey().equals(userRequest)) || (temp.getValue().equals(passwordRequest))) {

if (rules.get(id).equals("admin")) {

request.getRequestDispatcher("Admin.jsp").forward(request, response);


}
id++;
}

Can you give me some help.
Thank you.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "not working right" what do you mean? Is it not behaving as expected, or is there some sort of exception being thrown?
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess in your code string variable comparison fails and the code with in "IF" check is not executed. To compare string variables you could use "equalsIgnoreCase()" and "trim()" methods. Also try printing the variables so that you would know why the "IF" checks are failing.
 
Syskata Mitev
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oks. i have user = "admin" , password = "1" and rules = "admin" and i read from MySQL database and check with "admin" and "1" and wont to know the rule. when i put :


out.println("ID : " + id + " User : " + userRequest +
" Password : " + passwordRequest + "Rules : " + rules.get(id));

servlet return :

ID : 1 User : admin Password : 1Rules : visitor ID : 5 User : admin Password : 1Rules : user

So it's look does't work correctly. Look like i can't get id right or this is not a good way to do that. Why out.println run twice with wrong return?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic