Well I think I got it!! Thanks for the support. Here
is my final servlet. One last question...Is there
anything I can do to improve this app(besides using a
framework). Is it considered "thread-safe" and
efficient? Or Should these lines(
this.firstName=firstName;) be in the
MemberValidateForm() method instead of the validate
method?
thanks again
package com.bdi.www.members;
import java.util.*;
public class MemberValidateForm {
private String firstName;
private String lastName;
private String emailAddress;
private String homePhone;
private Map errors;
public boolean validate(String firstName,String
lastName,String emailAddress,String homePhone) {
this.firstName=firstName;
this.lastName=lastName;
this.emailAddress=emailAddress;
this.homePhone=homePhone;
boolean allOk=true;
if (firstName.equals("")) {
errors.put("firstName","Please enter your first
name");
firstName="";
allOk=false;
}
if (lastName.equals("")) {
errors.put("lastName","Please enter your last
name");
lastName="";
allOk=false;
}
if (emailAddress.equals("") ||
(emailAddress.indexOf('@') == -1)) {
errors.put("emailAddress","Please enter a valid
email address");
emailAddress="";
allOk=false;
}
if (homePhone.equals("")) {
errors.put("homePhone","Please enter your phone
number");
homePhone="";
allOk=false;
}
return allOk;
}
public MemberValidateForm() {
firstName="";
lastName="";
emailAddress="";
homePhone="";
errors = new HashMap();
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmailAddress() {
return emailAddress;
}
public String getHomePhone() {
return homePhone;
}
public void setFirstName(String firstName) {
this.firstName =firstName;
}
public void setLastName(String lastName) {
this.lastName =lastName;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress=emailAddress;
}
public void setHomePhone(String homePhone) {
this.homePhone=homePhone;
}
public Map getErrors() {
return errors;
}
}
__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail
|