I have written a jsp page and I have done the client side validation using java script. But now i am asked to do the server side validation in servets . Please help with the code. I tried many ways , but i am unable to do that. Please rescue
register.jsp
<%--
Document : test
Created on : Nov 1, 2010, 3:41:06 PM
Author : db2admin
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> Registration </title>
<script type="text/javascript">
function checkWholeForm(theForm)
{
var why = "";
why += checkname(theForm.username, "user name");
why += checkPassword(theForm.password);
if ( theForm.password.value != theForm.password2.value )
{
why += "The two passwords do not match. Please enter the same password twice.\n";
}
why += checkname(theForm.firstname, "first name");
why += checkname(theForm.lastname, "last name");
why += checkEmail(theForm.email);
why += checkPhone(theForm.phno);
if (why != "")
{
alert(why);
return false;
}
return true;
}
function checkname(fld, name)
{
var val = fld.value;
if ( val.length < 3 || val.length > 10 )
{
fld.focus();
return "You must enter a " + name + " minimum 3 characters long.\n";
}
return "";
}
function checkPassword(fld)
{
var val = fld.value;
if ( val.length < 4 || val.length > 10 )
{
fld.focus();
return "You must enter a password that is atleast 5 characters long.\n";
}
return "";
}
function checkEmail(fld)
{
var val = fld.value;
//relational algebra standard for checking the emails
var emailFilter=/^[\w\-\'\.]+\@([\w\-\']+\.)+[a-z]{2,6}$/i;
if ( ! (emailFilter.test(val)) )
{
fld.focus();
return "Please enter a valid email address.\n";
}
return "";
}
function checkPhone(fld)
{
var val = fld.value;
// strip out ALL non-numeric characters
var ph = val.replace(/[^\d]/g, "");
if ( ph.length != 10 )
{
fld.focus();
return "The phone number must contain 10 digits.\n";
}
return "";
}
</script>
</head>
<body bgcolor="lightblue">
<form name="myform" method="post" action="SuccessfulRegistration.jsp" onsubmit="return checkWholeForm(this);">
<form name="myform" method="post" action="/servlet/validates"
<center>
<table>
<tr>
<center> <th><h1 style="font-family:arial;color:black;font-size:20px;"><i>eOnline Auction</i></h1></th></center>
</tr>
</table>
<br>
<br>
<br>
<br>
<table border="1" cellspacing="1" cellpadding="0" align="center" width=300>
<tr>
<td colspan="2" bgcolor="lightblue"><center><b>Registration Form</b></center></td>
</tr>
<tr>
<td>UserName</td>
<td><input type="text" size="20" name="username"></td>
</tr>
<tr>
<td>Password </td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Confirm password </td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td> FirstName </td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td> LastName </td>
<td><input type="text" name="lastname"></td>
</tr>
<tr>
<td> Email </td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td> Address </td>
<td><input type="text" name="address"></td>
</tr>
<tr>
<td> Street </td>
<td><input type="text" name="street"></td>
</tr>
<tr>
<td> City </td>
<td><input type="text" name="city"></td>
</tr>
<tr>
<td> State </td>
<td><input type="text" name="state"></td>
</tr>
<tr>
<td> Zipcode </td>
<td><input type="text" name="zipcode"></td>
</tr>
<tr>
<td> Phonenumber </td>
<td><input type="text" name="phno"></td>
</tr>
<tr>
<td colspan ="2"><center><input type ="submit" value = "Register"></center></td>
</tr>
</table>
</center>
</form>
</body>
</html>