i have the following code but it has some sorts of error whenever i run the page after validation through javascript it calls for the servlets and then i tried to retrive the parameters but it is always showing me null values. My Html page is like this
<form action="sfkcreateaccount" method="post"> <table style="width: 940px"> <tr> <td style="width: 450px; margin: 5px; padding: 5px"> <div> <table> <tr> <td> First Name: </td> <td> <input type="text" id="fname" placeholder="First Name" style="width: 157px" maxlength="2048"> </td> </tr> <tr> <td> Last Name: </td> <td> <input type="text" id="lname" placeholder="Last Name" style="width: 157px" maxlength="2048"> </td> </tr> <tr> <td> Choose Password: </td> <td> <input type="password" id="pwd1" placeholder="Choose Password" style="width: 157px" maxlength="40"> </td> </tr> <tr> <td> Choose Username: </td> <td> <input type="text" id="uname1" placeholder="Choose Username" style="text-transform: lowercase; width: 157px;" maxlength="100"> </td> </tr> <tr> <td> Gender: </td> <td> <input type="radio" name="gender" value="Male" checked="checked" id="male"><label for="male">Male</label> <input type="radio" name="gender" value="Female" id="female"><label for="female">Female</label> </td> </tr> </table> </div> </td> <td style="width: 450px; margin: 5px;padding: 5px"> <div> <table> <tr> <td> Middle Name: </td> <td> <input type="text" id="mname" placeholder="Middle Name" style="width: 157px" maxlength="2048"> </td> </tr> <tr> <td> Date of Birth: </td> <td> <input type="date" id="dob" placeholder="MM/DD/YYYY" style="width: 157px"> </td> </tr> <tr> <td> Verify Password: </td> <td> <input type="password" id="pwd2" placeholder="Verify Password" style="width: 157px" maxlength="40"> </td> </tr> <tr> <td> Verify Username: </td> <td> <input type="text" id="uname2" placeholder="Verify Username" style="text-transform: lowercase; width: 157px" maxlength="100"> </td> </tr> <tr> <td> Country: </td> <td> <select style="width: 157px" id="cntri"> <option value="-1">Select Your Country</option> <option value="AF">Afghanistan</option> <option value="AX">Ã?â?¦land Islands </option> <option value="AL">Albania </option> <option value="DZ">Algeria </option> <option value="AS">American Samoa </option> <option value="AD">AndorrA </option> <option value="AO">Angola </option> <option value="AI">Anguilla </option> <option value="AQ">Antarctica </option> <option value="AG">Antigua and Barbuda</option> <option value="AR">Argentina </option> <option value="AM">Armenia </option> <option value="AW">Aruba </option> <option value="AU">Australia</option> <option value="AT">Austria </option> <option value="AZ">Azerbaijan </option> <option value="BS">Bahamas</option> <option value="BH">Bahrain </option> <option value="BD">Bangladesh </option> <option value="BB">Barbados </option> <option value="BY">Belarus </option> <option value="BE">Belgium </option> <option value="BZ">Belize </option> <option value="BJ">Benin</option> <option value="BM">Bermuda</option> <option value="BT">Bhutan</option> <option value="BO">Bolivia</option> <option value="BA">Bosnia and Herzegovina</option> <option value="BW">Botswana</option> <option value="BV">Bouvet Island</option> <option value="BR">Brazil</option> <option value="IO">British Indian Ocean Territory</option> <option value="BN">Brunei Darussalam</option> <option value="BG">Bulgaria</option> <option value="BF">Burkina Faso</option> <option value="BI">Burundi</option> <option value="KH">Cambodia </option> <option value="CM">Cameroon </option> <option value="CA">Canada </option> <option value="CV">Cape Verde </option> <option value="KY">Cayman Islands </option> <option value="CF">Central African Republic</option> <option value="TD">Chad </option> <option value="CL">Chile </option> <option value="CN">China </option> <option value="CX">Christmas Island </option> <option value="CC">Cocos (Keeling) Islands </option> <option value="CO">Colombia </option> <option value="KM">Comoros </option> <option value="CG">Congo </option> <option value="CD">Congo, The Democratic Republic of the </option> <option value="CK">Cook Islands </option> <option value="CR">Costa Rica </option> <option value="CI">Cote D'Ivoire </option> <option value="HR">Croatia </option> <option value="CU">Cuba </option> <option value="CY">Cyprus </option> <option value="CZ">Czech Republic </option> <option value="DK">Denmark</option> <option value="DJ">Djibouti</option> <option value="DM">Dominica</option> <option value="DO">Dominican Republic</option> <option value="EC">Ecuador</option> <option value="EG">Egypt</option> <option value="SV">El Salvador</option> <option value="GQ">Equatorial Guinea</option> <option value="ER">Eritrea</option> <option value="EE">Estonia</option> <option value="ET">Ethiopia</option> <option value="FK">Falkland Islands (Malvinas)</option> <option value="FO">Faroe Islands</option> <option value="FJ">Fiji</option> <option value="FI">Finland</option> <option value="FR">France</option> <option value="GF">French Guiana</option> <option value="PF">French Polynesia</option> <option value="TF">French Southern Territories</option> <option value="GA">Gabon</option> <option value="GM">Gambia</option> <option value="GE">Georgia</option> <option value="DE">Germany</option> <option value="GH">Ghana</option> <option value="GI">Gibraltar</option> <option value="GR">Greece</option> <option value="GL">Greenland</option> <option value="GD">Grenada</option> <option value="GP">Guadeloupe</option> <option value="GU">Guam</option> <option value="GT">Guatemala</option> <option value="GG">Guernsey</option> <option value="GN">Guinea</option> <option value="GW">Guinea-Bissau</option> <option value="GY">Guyana</option> <option value="HT">Haiti</option> <option value="HM">Heard Island and Mcdonald Islands</option> <option value="VA">Holy See (Vatican City State)</option> <option value="HN">Honduras</option> <option value="HK">Hong Kong</option> <option value="HU">Hungary</option> <option value="IS">Iceland</option> <option value="IN">India</option> <option value="ID">Indonesia</option> <option value="IR">Iran, Islamic Republic Of</option> <option value="IQ">Iraq</option> <option value="IE">Ireland</option> <option value="IM">Isle of Man</option> <option value="IL">Israel</option> <option value="IT">Italy</option> <option value="JM">Jamaica</option> <option value="JP">Japan</option> <option value="JE">Jersey</option> <option value="JO">Jordan</option> <option value="KZ">Kazakhstan</option> <option value="KE">Kenya</option> <option value="KI">Kiribati</option> <option value="KP">Korea, Democratic People'S Republic of</option> <option value="KR">Korea, Republic of</option> <option value="KW">Kuwait</option> <option value="KG">Kyrgyzstan</option> <option value="LA">Lao People'S Democratic Republic</option> <option value="LV">Latvia</option> <option value="LB">Lebanon</option> <option value="LS">Lesotho</option> <option value="LR">Liberia</option> <option value="LY">Libyan Arab Jamahiriya</option> <option value="LI">Liechtenstein</option> <option value="LT">Lithuania</option> <option value="LU">Luxembourg</option> <option value="MO">Macao</option> <option value="MK">Macedonia, The Former Yugoslav Republic of</option> <option value="MG">Madagascar</option> <option value="MW">Malawi</option> <option value="MY">Malaysia</option> <option value="MV">Maldives</option> <option value="ML">Mali</option> <option value="MT">Malta</option> <option value="MH">Marshall Islands</option> <option value="MQ">Martinique</option> <option value="MR">Mauritania</option> <option value="MU">Mauritius</option> <option value="YT">Mayotte</option> <option value="MX">Mexico</option> <option value="FM">Micronesia, Federated States of</option> <option value="MD">Moldova, Republic of</option> <option value="MC">Monaco</option> <option value="MN">Mongolia</option> <option value="MS">Montserrat</option> <option value="MA">Morocco</option> <option value="MZ">Mozambique</option> <option value="MM">Myanmar</option> <option value="NA">Namibia</option> <option value="NR">Nauru</option> <option value="NP">Nepal</option> <option value="NL">Netherlands</option> <option value="AN">Netherlands Antilles</option> <option value="NC">New Caledonia</option> <option value="NZ">New Zealand</option> <option value="NI">Nicaragua</option> <option value="NE">Niger</option> <option value="NG">Nigeria</option> <option value="NU">Niue</option> <option value="NF">Norfolk Island</option> <option value="MP">Northern Mariana Islands</option> <option value="NO">Norway</option> <option value="OM">Oman</option> <option value="PK">Pakistan</option> <option value="PW">Palau</option> <option value="PS">Palestinian Territory, Occupied</option> <option value="PA">Panama</option> <option value="PG">Papua New Guinea</option> <option value="PY">Paraguay</option> <option value="PE">Peru</option> <option value="PH">Philippines</option> <option value="PN">Pitcairn</option> <option value="PL">Poland</option> <option value="PT">Portugal</option> <option value="PR">Puerto Rico</option> <option value="QA">Qatar</option> <option value="RE">Reunion</option> <option value="RO">Romania</option> <option value="RU">Russian Federation</option> <option value="RW">RWANDA</option> <option value="SH">Saint Helena</option> <option value="KN">Saint Kitts and Nevis</option> <option value="LC">Saint Lucia</option> <option value="PM">Saint Pierre and Miquelon</option> <option value="VC">Saint Vincent and the Grenadines</option> <option value="WS">Samoa</option> <option value="SM">San Marino</option> <option value="ST">Sao Tome and Principe</option> <option value="SA">Saudi Arabia</option> <option value="SN">Senegal </option> <option value="CS">Serbia and Montenegro</option> <option value="SC">Seychelles</option> <option value="SL">Sierra Leone</option> <option value="SG">Singapore</option> <option value="SK">Slovakia</option> <option value="SI">Slovenia</option> <option value="SB">Solomon Islands</option> <option value="SO">Somalia</option> <option value="ZA">South Africa</option> <option value="GS">South Georgia and the South Sandwich Islands</option> <option value="ES">Spain</option> <option value="LK">Sri Lanka</option> <option value="SD">Sudan</option> <option value="SR">Suriname</option> <option value="SJ">Svalbard and Jan Mayen</option> <option value="SZ">Swaziland</option> <option value="SE">Sweden</option> <option value="CH">Switzerland</option> <option value="SY">Syrian Arab Republic</option> <option value="TW">Taiwan, Province of China</option> <option value="TJ">Tajikistan</option> <option value="TZ">Tanzania, United Republic of</option> <option value="TH">Thailand</option> <option value="TL">Timor-Leste</option> <option value="TG">Togo</option> <option value="TK">Tokelau</option> <option value="TO">Tonga</option> <option value="TT">Trinidad and Tobago</option> <option value="TN">Tunisia</option> <option value="TR">Turkey</option> <option value="TM">Turkmenistan</option> <option value="TC">Turks and Caicos Islands</option> <option value="TV">Tuvalu</option> <option value="UG">Uganda</option> <option value="UA">Ukraine</option> <option value="AE">United Arab Emirates</option> <option value="GB">United Kingdom</option> <option value="US">United States</option> <option value="UM">United States Minor Outlying Islands</option> <option value="UY">Uruguay</option> <option value="UZ">Uzbekistan</option> <option value="VU">Vanuatu</option> <option value="VE">Venezuela</option> <option value="VN">Viet Nam</option> <option value="VG">Virgin Islands, British</option> <option value="VT">Virgin Islands, U.S.</option> <option value="WF">Wallis and Futuna</option> <option value="EH">Western Sahara</option> <option value="YE">Yemen</option> <option value="ZM">Zambia</option> <option value="ZW">Zimbabwe</option> </select> </td> </tr> </table> </div> </td> </tr> </table> <div style="text-align: center;padding-top: 20px"> <input id="Create_Account_Control" type="submit" value="Create My New Account" style="border-width: 2px; border-radius: 6px; border-color: threeddarkshadow; background-color: snow; width: 180px; height: 25px;" onmousedown="musdown()" onmouseout="musout()" onmouseover="musover()" onmouseup="musup()" onkeypress="musdown()"> </div> </form>
After This i added Java Scripts by following
function musup() { document.getElementById('Create_Account_Control').style.backgroundColor='#6f6'; document.getElementById("Create_Account_Control").style.borderColor='threedshadow'; document.getElementById("Create_Account_Control").style.fontStyle='italic'; document.getElementById("Create_Account_Control").style.fontWeight='bold'; } function musdown() { document.getElementById('Create_Account_Control').style.backgroundColor='lightblue'; document.getElementById("Create_Account_Control").style.borderColor='threedshadow'; document.getElementById("Create_Account_Control").style.fontStyle='oblique'; document.getElementById("Create_Account_Control").style.fontWeight='bold'; click_action(); } function musover() { document.getElementById('Create_Account_Control').style.backgroundColor='#6f6'; document.getElementById("Create_Account_Control").style.borderColor='threedshadow'; document.getElementById("Create_Account_Control").style.fontStyle='italic'; document.getElementById("Create_Account_Control").style.fontWeight='bold'; } function musout() { document.getElementById('Create_Account_Control').style.backgroundColor='snow'; document.getElementById("Create_Account_Control").style.borderColor='threeddarkshadow'; document.getElementById("Create_Account_Control").style.fontStyle='normal'; document.getElementById("Create_Account_Control").style.fontWeight='normal'; } function click_action() { var fname,mname,lname,pwd1,pwd2,uname1,uname2,gender,cntri,t,dob_year,dob_month,dob_date,current_year,current_month,current_date,temp,dob,current; t=new Date(); fname=document.getElementById("fname").value; mname=document.getElementById("mname").value; lname=document.getElementById("lname").value; t=document.getElementById("dob").value; pwd1=document.getElementById("pwd1").value; pwd2=document.getElementById("pwd2").value; uname1=document.getElementById("uname1").value; uname2=document.getElementById("uname2").value; cntri=document.getElementById("cntri").value; temp=document.getElementsByName("gender"); dob=new Date(t); current=new Date(); dob_year=dob.getFullYear(); dob_month=dob.getMonth(); dob_date=dob.getDate(); current_year=current.getFullYear(); current_month=current.getMonth(); current_date=current.getDate(); if(fname.length<=0||mname.length<=0||lname.lenght<=0||pwd1.lenght<=0||pwd2.length<=0||uname1.length<=0||uname2.lenght<=0||cntri==-1) { alert("Please Fill All the Fields First"); } else { if(t==null) { alert("Please Select your Birth Date") } else { if(current_year>=dob_year) { if(current_month>=dob_month) { if(current_date>dob_date) { if(temp[0].checked == true || temp[1].checked == true ) { if(temp[0].checked==true) { gender=temp[0].value; } if(temp[1].checked==true) { gender=temp[1].value; } validity(); } else { alert("Please Select a Gender"); } } else { alert("Invalid Date"); } } else { alert("Invalid month"); } } else { alert("Invalid Year"); } } } } function validity() { var pwd1,pwd2,uname1,uname2; pwd1=document.getElementById("pwd1").value; pwd2=document.getElementById("pwd2").value; uname1=document.getElementById("uname1").value; uname2=document.getElementById("uname2").value; uname1.toString().toLowerCase(); uname2.toString().toLowerCase(); if(pwd1==pwd2) { if(uname1==uname2) { Name_validaton(); } else { alert("Usernames didn't matches"); } } else { alert("Passwords didn't matches"); } } function Name_validaton() { var fname,mname,lname; fname=document.getElementById("fname").value; mname=document.getElementById("mname").value; lname=document.getElementById("lname").value; f=String(fname); m=String(mname); l=String(lname); A0=String("?"); A1=String("|"); A2=String("\\"); A3=String("["); A4=String("+"); A5=String(")"); A6=String("("); A7=String("*"); A8=String("&"); A9=String("^"); B0=String("$"); B1=String("$"); B2=String("$"); if(f.match("@")||m.match("@")||l.match("@")||f.match("!")||m.match("!")||l.match("!")||f.match("~")||m.match("~")||l.match("~")||f.match("`")||m.match("`")||l.match("`")||f.match("%")||m.match("%")||l.match("%")||f.match("#")||m.match("#")||l.match("#")||f.match("_")||m.match("_")||l.match("_")||f.match("=")||m.match("=")||l.match("=")||f.match("}")||m.match("}")||l.match("}")||f.match("{")||m.match("{")||l.match("{")||f.match("]")||m.match("]")||l.match("]")||f.match("\"")||m.match("\"")||l.match("\"")||f.match("'")||m.match("'")||l.match("'")||f.match(";")||m.match(";")||l.match(";")||f.match(":")||m.match(":")||l.match(":")||f.match(",")||m.match(",")||l.match(",")||f.match("<")||m.match("<")||l.match("<")||f.match(">")||m.match(">")||l.match(">")||f.match("/")||m.match("/")||l.match("/")||f.match("0")||f.match("1")||f.match("2")||f.match("3")||f.match("4")||f.match("5")||f.match("6")||f.match("7")||f.match("8")||f.match("9")||m.match("0")||m.match("1")||m.match("2")||m.match("3")||m.match("4")||m.match("5")||m.match("6")||m.match("7")||m.match("8")||m.match("9")||l.match("0")||l.match("1")||l.match("2")||l.match("3")||l.match("4")||l.match("5")||l.match("6")||l.match("7")||l.match("8")||l.match("9")) { alert("Invalid Character in Name"); /*if(f.match(B0)||m.match(B0)||l.match(B0)||f.match(B1)||m.match(B1)||l.match(B1)||f.match(B2)||m.match(B2)||l.match(B2)||f.match(A0)||m.match(A0)||l.match(A0)||f.match(A1)||m.match(A1)||l.match(A1)||f.match(A2)||m.match(A2)||l.match(A2)||f.match(A3)||m.match(A3)||l.match(A3)||f.match(A4)||m.match(A4)||l.match(A4)||f.match(A5)||m.match(A5)||l.match(A5)||f.match(A6)||m.match(A6)||l.match(A6)||f.match(A7)||m.match(A7)||l.match(A7)||f.match(A8)||m.match(A8)||l.match(A8)||f.match(A9)||m.match(A9)||l.match(A9)) { }*/ } else { custname_validation(); } } function custname_validation() { var pwd1,pwd2,uname1,uname2; pwd1=document.getElementById("pwd1").value; pwd2=document.getElementById("pwd2").value; uname1=document.getElementById("uname1").value; uname2=document.getElementById("uname2").value; u1=String(uname1); u2=String(uname2); if(pwd1.length<=7||pwd2.length<=7) { alert("Password Must be between 8 to 40"); } else { if(uname1.length<=4||uname2.length<=4) { alert("Username Must be between 5 to 100"); } else { if(u1.match("-")||u2.match("-")||u1.match("_")||u2.match("_")||u1.match(".")||u2.match(".")||u1.match("0")||u2.match("0")||u1.match("1")||u2.match("1")||u1.match("2")||u2.match("2")||u1.match("3")||u2.match("3")||u1.match("4")||u2.match("4")||u1.match("5")||u2.match("5")||u1.match("6")||u2.match("6")||u1.match("7")||u2.match("7")||u1.match("8")||u2.match("8")||u1.match("9")||u2.match("9")||u1.match("a")||u2.match("a")||u1.match("b")||u2.match("b")||u1.match("c")||u2.match("c")||u1.match("d")||u2.match("d")||u1.match("e")||u2.match("e")||u1.match("f")||u2.match("f")||u1.match("g")||u2.match("g")||u1.match("h")||u2.match("h")||u1.match("i")||u2.match("i")||u1.match("j")||u2.match("j")||u1.match("k")||u2.match("k")||u1.match("l")||u2.match("l")||u1.match("m")||u2.match("m")||u1.match("n")||u2.match("n")||u1.match("o")||u2.match("o")||u1.match("p")||u2.match("p")||u1.match("q")||u2.match("q")||u1.match("r")||u2.match("r")||u1.match("s")||u2.match("s")||u1.match("t")||u2.match("t")||u1.match("u")||u2.match("u")||u1.match("v")||u2.match("v")||u1.match("w")||u2.match("w")||u1.match("x")||u2.match("x")||u1.match("y")||u2.match("y")||u1.match("z")||u2.match("z")) { submiting(); } else { alert("Only [-,_,.],[0-9],[a-z] characters are allowed"); } } } //document.getElementById("Create_Account_Control").disabled=true; } function submiting() { submit(); }
And at the End i created Servlet page:
package Classfiles; import java.io.IOException; import java.io.PrintWriter; import java.sql.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class sfkcreateaccount extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String fname,mname,lname,uname, pwd,cntri,gender; Date dob; java.util.Date db1; //db1=new java.util.Date(request.getParameter("dob")); fname=request.getParameter("fname"); mname=request.getParameter("mname"); lname=request.getParameter("lname"); uname=request.getParameter("uname2"); pwd=request.getParameter("pwd2"); //dob=(Date) db1; out.println(fname); out.println(mname); out.println(lname); out.println(uname); out.println(pwd); //out.println(dob.toString()); } @Override public String getServletInfo() { return "Short description"; } }
This Servlets always showing me null value So can any one tell me what to do to remove this error I also want to optimise the code so please help me.
Ads