• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HashMap problem

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
reply
    Bookmark Topic Watch Topic
  • New Topic