Java Reference
In-Depth Information
id = rs.getInt("MemberID");
memberPwd = rs.getString("Password");
}
con.close();
stmt.close();
}catch(ClassNotFoundException e1){
System.err.println(e1.getMessage());
}catch(SQLException e2){
System.err.println(e2.getMessage());
}
if(id==-1){
return "New Member";
}else if(!memberPwd.equals(password)){
return "Bad Password";
}else{
return "Member#"+id;
}
}
}
Note
In order to use the "*" wildcard to set JavaBean properties from a JSP page, the
property names must match the variable names used in the HTML form. Property
names are case sensitive.
The LoginBean of Listing 12-9 returns a String indicating the user's login status. The three possible
return values are as follows:
 
"New Member"
 
"Bad Password"
 
"Member#nnn"
The JSP page deals with each of these possible return values by forwarding the user to the appropriate
JSP page. In the case of a registered member, the user is simply forwarded to the welcome page of the
main site. Someone logging on with an unknown user name is considered a new member and is
forwarded to the Member Registration trail, discussed in the next chapter . If the user name is
recognized, but the password is not, the user is offered the option of retrying, signing on as a new
member, or having the correct password sent to his or her e-mail address.
Summary
This chapter gives you a look at the use of the JDBC DataSource object as a means of obtaining
database connections. Other topics covered include the following:
 
Creating Dynamic Web Pages
 
Using the HttpServlet object
 
Implementing a Membership Web Site
 
Using Java Server Pages
 
Using JavaBeans with Java Server Pages
Chapter 13 covers creating and populating the basic membership database tables. The examples are
based on the use of PreparedStatements and CallableStatements .
Search WWH ::




Custom Search