i created a multi form registration page in jsp. when user presses submission button it has to validate the data and redirected to success page but its not redirecting and validating can someone help.(no data in database too) im new to this subject please be kind to help.
register.jsp
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form action="process.jsp" id="msform" method="post">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">Personal Details</li>
<li>Contact Details</li>
<li>Security details</li>
<li>Almost Done</li>
</ul>
<!-- fieldsets -->
<fieldset>
<h2 class="fs-title"></h2>
<h3 class="fs-subtitle">Please Fill in the fields in Latin characters only</h3>
<input type="text" name="fname" placeholder="First Name"/>
<input type="text" name="lname" placeholder="Last Name" />
<input type="text" name="email" placeholder="Email Address" pattern="[^ @]*@[^ @]*"/>
<input type="email" name="email" placeholder="Re Enter Email Address" />
<input id="dob" name="dateOfBirth" type="date" placeholder="Date of birth"/>
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title"></h2>
<h3 class="fs-subtitle"><h3 class="fs-subtitle">Please Fill in the fields in Latin characters only</h3>
<input type="text" name="address" placeholder="Address"/>
<input type="text" name="address" placeholder=""/></textarea>
<input type="text" name="city" placeholder="City" />
<input type="text" name="zip" placeholder="Zip/Postal Code" />
<select name="country" id="country">
<option value="0" selected="selected">Country</option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="American Samoa">American Samoa</option>
<option value="Andorra">Andorra</option>
<option value="Angola">Angola</option>
<option value="Anguilla">Anguilla</option>
<option value="Antigua & Barbuda">Antigua & Barbuda</option>
<option value="Argentina">Argentina</option>
<option value="Armenia">Armenia</option>
<option value="Aruba">Aruba</option>
<option value="Australia">Australia</option>
<option value="Austria">Austria</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Zimbabwe">Zimbabwe</option>
</select>
<br></br><br></br>
<input type="text" name="phone" placeholder="Phone" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title"></h2>
<h3 class="fs-subtitle">Please Fill in the fields in Latin characters only</h3>
<input type="password" name="pass" placeholder="Password" />
<input type="password" name="cpass" placeholder="Confirm Password"/>
<select name="questions" id="secquest">
<option value="0" selected="selected">Security Questions</option>
<option value="school">What was the name of your primary school?</option>
<option value="father">In what year was your father born?</option>
<option value="time">What time of the day were you born? (hh:mm)</option>
<option value="wedding">What is the name of the place your wedding reception was held?</option>
</select>
<br></br><br></br>
<input type="text" name="answer" placeholder="Security Answer" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset>
<h2 class="fs-title"></h2>
<h3 class="fs-subtitle">Terms and conditions</h3>
<input type="checkbox" name="your-group" id="chkbox1" value="unit-in-group" /> I agree to the <a href="">Electronic and Cookie Disclosures</a> and <a href="">Privacy policy</a><br></br>
<input type="checkbox" name="your-group" id="chkbox2" value="unit-in-group" /> I agree to the <a href="">Terms and Conditions</a> and <a href="">LK Payment Service Terms and Conditions</a><br></br>
<input type="checkbox" name="your-group" id="chkbox3" value="unit-in-group" /> I agree to the <a href="">Prices and Fees</a> <br></br>
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="submit" name="submit" class="submit action-button" value="Submit" />
</fieldset>
</form>
</body>
<!-- jQuery -->
<script src="jquery/jquery-1.9.1.js" type="text/javascript"></script>
<script src="jquery/one.js" type="text/javascript"></script>
<!-- jQuery easing plugin -->
<script src="jquery/jquery.easing-1.3.min.js" type="text/javascript"></script>
</html>
process.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="register.RegistrationDetails" %>
<%!%>
<jsp:useBean id="formHandler" class="register.RegistrationDetails" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<%
if (formHandler.validate())
{
formHandler.insertData();%>
<jsp:forward page="success.jsp"/>
<% }
else {
%>
<jsp:forward page="retry.jsp"/>
<%}%>
retry.jsp
<jsp:useBean id="formHandler" class="register.RegistrationDetails" scope="request"/>
<html>
<body>
<form action="process.jsp" method=post>
<center>
<table cellpadding=4 cellspacing=2 border=0>
<th bgcolor="lightblue" colspan=2>
<font size=5>User Registration</font>
<br>
<font size=2 color="red"><sup>*</sup> Required Fields </font>
</th>
<tr bgcolor="lightblue">
<td valign=top>
<B>First Name<sup>*</sup></B>
<br>
<input type="text" name="firstName"
value='<%=formHandler.getFirstName()%>' size=15 maxlength=20>
<br><font size=2
color=red><%=formHandler.getErrorMsg("firstName")%></font>
</td>
<td valign=top>
<B>Last Name<sup>*</sup></B>
<br>
<input type="text" name="lastName"
value='<%=formHandler.getLastName()%>' size=15 maxlength=20>
<br><font size=2
color=red><%=formHandler.getErrorMsg("lastName")%></font>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top>
<B>E-Mail<sup>*</sup></B>
<br>
<input type="text" name="email" value='<%=formHandler.getEmail()%>'
size=25 maxlength=125>
<br><font size=2 color=red><%=formHandler.getErrorMsg("email")%></font>
</td>
<td valign=top>
<B>Cell Nr(9 fig.)<sup>*</sup></B>
<br>
<input type="text" name="zip" value='<%=formHandler.getZip()%>' size=5
maxlength=9>
<br><font size=2 color=red><%=formHandler.getErrorMsg("zip")%></font>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top colspan=2>
<B>User Name<sup>*</sup></B>
<br>
<input type="text" name="userName" size=10
value='<%=formHandler.getUserName()%>' maxlength=10>
<br><font size=2
color=red><%=formHandler.getErrorMsg("userName")%></font>
</td>
</tr>
<tr bgcolor="lightblue">
<td valign=top>
<B>Password<sup>*</sup></B>
<br>
<input type="password" name="password1" size=10
value='<%=formHandler.getPassword1()%>' maxlength=10>
<br><font size=2
color=red><%=formHandler.getErrorMsg("password1")%></font>
</td>
<td valign=top>
<B>Confirm Password<sup>*</sup></B>
<br>
<input type="password" name="password2" size=10
value='<%=formHandler.getPassword2()%>' maxlength=10>
<br><font size=2
color=red><%=formHandler.getErrorMsg("password2")%></font>
</td>
<br>
</tr>
<tr bgcolor="lightblue">
<td colspan=2 align=center>
<input type="submit" value="Submit">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
success.java
<html>
<body>
<center>
<span style="font-size: x-large;">User Registration Successful!</span>
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td valign="top"><strong>First Name</strong></td>
<td valign="top"><strong>Last Name</strong></td>
<td valign="top"><strong>E-Mail</strong></td>
<td valign="top"><strong>Age</strong></td>
<td valign="top"><strong>City</strong></td>
<td valign="top"><strong>Zip Code</strong></td>
<td colspan="2" valign="top"><strong>User Name</strong></td>
</tr>
</table>
</center>
</body></html>
RegistrationDetails.java
package register;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Date;
public class RegistrationDetails
{
private String fname,lname,email,address,address2,city,zip,country,phone,pass,cpass,questions,answer,notify;
private Date dateOfBirth = null;
private Hashtable errors;
private Connection connection=null;
Statement st;
public boolean validate() {
boolean bool=true;
if (fname.equals(""))
{
errors.put("fname","Please enter your first name");
fname="";
bool=false;
}
if (lname.equals(""))
{
errors.put("lname","Please enter your last name");
lname="";
bool=false;
}
if (email.equals("") || (email.indexOf('@') == -1))
{
errors.put("email","Please enter a valid email address");
email="";
bool=false;
}
if (dateOfBirth.equals(""))
{
errors.put("dateOfBirth","Please enter your first name");
dateOfBirth=null;
bool=false;
}
if (address.equals(""))
{
errors.put("address","Please enter your city name");
address="";
bool=false;
}
if (city.equals(""))
{
errors.put("city","Please enter your city name");
city="";
bool=false;
}
if (zip.equals("") || zip.length() !=6 )
{
errors.put("zip","Please enter a valid zip code");
zip="";
bool=false;
}
else
{
try {
int x = Integer.parseInt(zip);
} catch (NumberFormatException e)
{
errors.put("zip","Please enter a valid zip code");
zip="";
bool=false;
}
}
if (country.equals(""))
{
errors.put("country","Please select a country");
country="";
bool=false;
}
if (phone.equals("") || phone.length() !=12 )
{
errors.put("phone","Please enter a valid phone number");
phone="";
bool=false;
}
else
{
try {
int x = Integer.parseInt(phone);
} catch (NumberFormatException e)
{
errors.put("phone","Please enter a valid phone number");
phone="";
bool=false;
}
}
if (questions.equals(""))
{
errors.put("questions","Please select a security question");
questions="";
bool=false;
}
if (answer.equals(""))
{
errors.put("answer","Please answer the security question");
answer="";
bool=false;
}
if (pass.equals("") )
{
errors.put("pass","Please enter a valid password");
pass="";
bool=false;
}
if (!pass.equals("") && (cpass.equals("") || !pass.equals(cpass)))
{
errors.put("cpass","Please confirm your password");
cpass="";
bool=false;
}
return bool;
}
public String getErrorMsg(String s)
{
String errorMsg =(String)errors.get(s.trim());
return (errorMsg == null) ? "":errorMsg;
}
public void insertData()
{
try {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (Exception ex)
{
System.out.println("Error in class.forname"+ex.getCause());
Logger.getLogger(RegistrationDetails.class.getName()).log(Level.SEVERE, null, ex);
}
connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/registrationform","root", "");
st= (Statement) connection.createStatement();
String table = "create table if not exists users(First_Name varchar(20),Last_Name varchar(20),EmailAddress varchar(40),Age int(4),City varchar(15),Zip_Code varchar(10),UserName varchar(15),Password varchar(15))";
st.executeUpdate(table);
fname=getFirstName();
lname=getLastName();
email=getEmail();
dateOfBirth=getDateOfBirth();
city=getCity();
zip=getZip();
country=getCountry();
pass=getPass();
st.executeUpdate("INSERT INTO USERSINSERT INTO users(`first_name`, `last_name`, `date_of_birth`,`email`, `password`, `address`, `address2`, `city`, `zipcode`, `country`, `phone`, `questions`, `answers`) "
+ "values('"+fname+"','"+lname+"','"+dateOfBirth+"','"+email+"','" +pass+"','"+address+"','"+address2+"','"+city+"','"+zip+"','"+country+"','"+phone+"','"+questions+"','"+answer+"')");
System.out.println("Store into the database");
} catch (Exception ex)
{
System.out.println("Error in connection::"+ex.getCause());
}
}
public RegistrationDetails()
{
fname="";lname="";email="";address="";city="";zip="";country="";phone="";pass="";cpass="";questions="";answer="";notify="";errors = new Hashtable();
}
public String getFirstName() {
return fname;}
public String getLastName() {
return lname;}
public String getEmail() {
return email;}
public String getAddress() {
return lname;}
public String getPhone() {
return phone;}
public String getQuestions() {
return questions;}
public String getAnswers() {
return answer;}
public Date getDateOfBirth() {
return dateOfBirth;
}
public String getCountry() {
return country;}
public String getPass() {
return pass;}
public String getComPassword() {
return cpass;}
public String getCity() {
return city;}
public String getZip() {
return zip;}
public void setFirstName(String firstname) {
fname =firstname;}
public void setLastName(String lastname) {
lname =lastname;}
public void setEmail(String eml) {
email=eml;}
public void setDateOfBirth(Date dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public void setPass(String pwd) {
pass=pwd;}
public void setComPass(String pwd2) {
cpass=pwd2;}
public void setCity(String city) {
this.city=city;}
public void setZip(String z) {
zip=z;}
public void setAddress(String addr) {
address=addr;}
public void setCoountry(String country) {
this.country=country;}
public void setQuestions(String questions) {
this.questions=questions;}
public void setAnswers(String anw) {
answer=anw;}
}
Aucun commentaire:
Enregistrer un commentaire