aspose file tools*
The moose likes Beginning Java and the fly likes HashMap problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap problem" Watch "HashMap problem" New topic
Author

HashMap problem

Syskata Mitev
Ranch Hand

Joined: Aug 23, 2006
Posts: 51
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

Joined: Apr 14, 2004
Posts: 10336

By "not working right" what do you mean? Is it not behaving as expected, or is there some sort of exception being thrown?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
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

Joined: Aug 23, 2006
Posts: 51
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashMap problem