JSP 2.0 p459 logic errata Chapter 12
In UserList.java the author wrote:
for (int iCount = 0; iCount < list.size(); iCount++)
{
if (user.getUserName == temp.getUserName()) && ...
return true;
else
return false;
}
return true;
-----------------------------------------------
To me this says if the first name in the list of users is a match,
then exit the for loop and signify that we have a valid user.
Otherwise, exit the loop and signify that we didn't find a valid user.
In other words, the above code doesn't check to see if the other users in the list are valid or not.
Here is the code I used to get the program to work:
public boolean isValidUser(User user)
{
for (int iCount = 0; iCount < list.size(); iCount++)
{
User temp = (User) list.get(iCount);
if (user.getUserName().equals(temp.getUserName())
&& user.getPassword().equals(temp.getPassword()))
return true;
}
return false;
}
This code says, go through the entire list. If we find a match, jump out of the loop and signify that the user is valid. If we make it through the loop and still haven't found a match then signify that the user is not valid by returning false.
Cheers,
newtonian
|