Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2004, 01:18 AM
Registered User
 
Join Date: Jul 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP 2.0 p457 errata Chapter 12 newtonian JSP Basics 0 March 10th, 2004 02:04 PM
JSP 2.0 p458 errata Chapter 12 newtonian JSP Basics 0 March 10th, 2004 01:53 PM
JSP 2.0 p459 errata Chapter 12 newtonian JSP Basics 0 March 10th, 2004 01:42 PM
JSP 2.0 p484 errata newtonian JSP Basics 3 February 23rd, 2004 10:56 PM
JSP 2.0 p492 errata newtonian JSP Basics 0 July 24th, 2003 12:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.