Java Reference
In-Depth Information
INSERT_CONTACT_INFO(?,?,?,?,?,?,?,?,?,?)}");
cs.setInt(1,id);
cs.setString(2,firstName);
cs.setString(3,String.valueOf(mi));
cs.setString(4,lastName);
cs.setString(5,street);
cs.setString(6,city);
cs.setString(7,state);
cs.setString(8,zip);
cs.setString(9,"<NULL>");
cs.setString(10,email);
if(cs.executeUpdate()!=1) username_selection_ok = false;
}
}catch(ClassNotFoundException e1){
System.err.println(e1.getMessage());
}catch(SQLException e2){
System.err.println(e2.getMessage());
}
return username_selection_ok;
}
}
Error Handling
Recall that the ProcessNABean notifies the ProcessNAForm.jsp page that the user needs to select
a different username by setting the boolean flag username_selection_ok to false. This lets the
ProcessNAForm.jsp know that a problem has arisen, so it then sends the user back to the form so he
or she can select a new username and password.
As it stands, the form is cleared when redisplayed. This is virtually guaranteed to ensure that the user
gets fed up and surfs on. The way to avoid this is to fill in the fields the user has already completed and
to present a message telling him or her what to do next.
One of the primary uses of JavaBeans in JSP applications is data storage. Since all the form data has
already been inserted into the ProcessNABean , completing the form for the user requires only the
addition of this line:
<jsp:useBean id="ProcessNABean".../>
Also, include these few extra lines of code to set the properties:
First Name<BR><INPUT maxLength=30 name=firstName
value='<jsp:getProperty name="ProcessNABean" property="firstName"/>'
size=26>
A partial listing of the modified form is shown in Listing 13-8 .
Listing 13-8: ProcessNAForm.jsp modified for use as an error page
Search WWH ::




Custom Search