Java Tutorial - Java Script : Handling the Registration Form

Java Tutorial - Java Script :

Handling the Registration Form


<TD width=”35%”>
<FONT size=”3”><B>Email Address</B></FONT>
</TD>
<TD width=”65%”>
<INPUT size=”58” type=”text” name=”EMAIL”>
</TD>
</TR>
<TR>
<TD width=”35%”></TD>
<TD width=”65%”>
Choose a user ID and password that you will use to access the members section and to update your user information.
</TD>
</TR>
<TR>
<TD width=”35%”>
<FONT size=”3”>
<B>User ID</B>
</FONT>
</TD>
<TD width=”65%”>
<INPUT size=”15” type=”text” name=”USERID”>
</TD>
</TR>
<TR>
<TD width=”35%”>
<FONT size=”3”><B>Password</B></FONT>
</TD>
<TD width=”65%”>
<INPUT size=”15” type=”password” name=”PASSWD1”>
</TD>
</TR>
<TR>
<TD width=”35%”>
<FONT size=”3”>
<B>Verify Password</B>
</FONT>
</TD>
<TD width=”65%”>
<INPUT size=”15” type=”password” name=”PASSWD2”>
</TD>
</TR>
<TR>
<TD colspan=”2”>
<HR>
</TD>
</TR>
<TR>
<TD width=”35%”><html:submit /></TD>
<TD width=”65%”><html:reset /></TD>
</TR>
</TBODY>
</TABLE>
</html:form>
<html:errors/>
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>

From a brief inspection of the preceding source code, we see that when our form is submitted, the HTML taglib specifies the action registerform. The action mapping follows for convenience.

<action path=”/registerform”
type=”RegisterAction”
name=”registerForm”
validate=”true”
input=”/register.jsp”>
<forward name =”main” path=”/main.jsp” />
</action>
Our registration form will be validated with the registerForm form bean, which is mapped to the RegisterForm class instance. The validate() method will be invoked because the validate attribute is set to true, and if an error occurs, control will be transferred back to the register.jsp view. The code for the RegisterForm class is shown below

import javax.servlet.http.*;
import org.apache.struts.action.*;
public class RegisterForm extends ActionForm
{
private String mFName = null;
private String mMName = null;
private String mLName = null;
private String mMDName = null;
private String mGradYear = null;
private String mFaculty = null;
private String mCity = null;
private String mState = null;
private String mEmail = null;
private String mUserID = null;
private String mPasswd1 = null;
private String mPasswd2 = null;
public String getFNAME()
{
return mFName;
}
public void setFNAME(String aFName)
{
mFName = aFName;
}
public String getMNAME()
{
return mMName;
}
public void setMNAME(String aMName)
{
mMName = aMName;
}
public String getLNAME()
{
return mLName;