This login.html for registration form
<html>
</head>
<title>registration form</title>
</head>
<body bgcolor="wheat">
<br>
<center><h2>Registration Form</h2></center>
<center>
<form action="login.do" method="post" >
<table border="0" align="center">
<tr>
<td>Name<span class="mandatory"></span></td><br></br>
<td><input type="text" name="name" maxlength="20"></td>
</tr>
<tr>
<td>UserName<span class="mandatory">*</span></td>
<td><input type="text" name="username" maxlength="20"></td>
</tr>
<tr>
<td>Password<span class="mandatory">*</span></td>
<td><input type="password" name="password" maxlength="25"></td>
</tr>
<tr>
<td>ConfirmPassword<span class="mandatory">*</span></td>
<td><input type="password" name="repassword" maxlength="25"></td>
</tr>
<tr>
<td>Date of Birth </td>
<td><input type="text" name="dob" maxlength="25">
<!-- <SELECT style="width:55px;font-family: MS Sans serif, arial, Verdana, sans-serif;font-size : 9pt" >
<option value="">DD
<option value="1" >1
<option value="2" >2
<option value="3" >3
<option value="4" >4
<option value="5" >5
<option value="6" >6
<option value="7" >7
<option value="8" >8
<option value="9" >9
<option value="10" >10
<option value="11" >11
<option value="12" >12
<option value="13" >13
<option value="14" >14
<option value="15" >15
<option value="16" >16
<option value="17" >17
<option value="18" >18
<option value="19" >19
<option value="20" >20
<option value="21" >21
<option value="22" >22
<option value="23" >23
<option value="24" >24
<option value="25" >25
<option value="26" >26
<option value="27" >27
<option value="28" >28
<option value="29" >29
<option value="30" >30
<option value="31" >31
</select>
<SELECT style="width:55px;font-family: MS Sans serif, arial,Verdana, sans-serif;font-size : 9pt">
<option value="">MM
<option value="1" >1
<option value="2" >2
<option value="3" >3
<option value="4" >4
<option value="5" >5
<option value="6" >6
<option value="7" >7
<option value="8" >8
<option value="9" >9
<option value="10" >10
<option value="11" >11
<option value="12" >12
</select>
<SELECT style="width:55px;font-family: MS Sans serif, arial, Verdana, sans-serif;font-size : 9pt">
<option value="">YYYY
<option value="2008" >2008
<option value="2007" >2007
<option value="2006" >2006
<option value="2005" >2005
<option value="2004" >2004
<option value="2003" >2003
<option value="2002" >2002
<option value="2001" >2001
<option value="2000" >2000
<option value="1999" >1999
<option value="1998" >1998
<option value="1997" >1997
<option value="1996" >1996
<option value="1995" >1995
<option value="1994" >1994
<option value="1993" >1993
<option value="1992" >1992
<option value="1991" >1991
<option value="1990" >1990
<option value="1989" >1989
<option value="1988" >1988
<option value="1987" >1987
<option value="1986" >1986
<option value="1985" >1985
<option value="1984" >1984
<option value="1983" >1983
<option value="1982" >1982
<option value="1981" >1981
<option value="1980" >1980
<option value="1979" >1979
<option value="1978" >1978
<option value="1977" >1977
<option value="1976" >1976
<option value="1975" >1975
<option value="1974" >1974
<option value="1973" >1973
<option value="1972" >1972
<option value="1971" >1971
<option value="1970" >1970
<option value="1969" >1969
<option value="1968" >1968
<option value="1967" >1967
<option value="1966" >1966
<option value="1965" >1965
<option value="1964" >1964
<option value="1963" >1963
<option value="1962" >1962
<option value="1961" >1961
<option value="1960" >1960
<option value="1959" >1959
<option value="1958" >1958
<option value="1957" >1957
<option value="1956" >1956
<option value="1955" >1955
<option value="1954" >1954
<option value="1953" >1953
<option value="1952" >1952
<option value="1951" >1951
<option value="1950" >1950
</select> -->
<font size="1" color="#7D7D7D"></font>
</td>
</tr>
<tr>
<!--<td>Gender</td>
<td valign="top" class="text1" colspan="2">
<input type="radio" name="gender" value="F" >Female
<input type="radio" name="gender" value="M" >Male
</td> -->
</tr>
<tr>
<td>Blood Group*</td>
<td colspan="2">
<input type="text" name="bloodgroup" size=5 maxlength=3></td> </tr>
<tr><td>Weight*</b></td>
<td><input type="text" name="weight" size=5 maxlength=3> Kgs<br></td>
</tr>
<tr>
<td>Mobile</td>
<td>
<table border="0">
<tr><td valign="top" align="center"><br><INPUT TYPE="text" NAME="mobileno" value=""></td></tr>
<!--<tr><td valign="top" align="center">Res<br><INPUT TYPE="text" NAME="res1" value=""></td></tr>
<td valign="top" align="center">Off<br><INPUT TYPE="text" NAME="off1" value=""></td>
</tr>--></table>
</td>
</tr>
<tr>
<td>E-mail id*</td>
<td>
<input type="text" size="20" NAME="email" value="" ><br>
</td>
</td>
</tr>
<td>State</td>
<td colspan="2">
<input type="text" name="state" size=5 maxlength=3>
<!--<SELECT style="width:150px;font-family:Verdana;font-size : 9pt" NAME="state" size="1">
<option value="">select state</td>
</tr>
<tr>
<td>City</td>
<TD colspan="2">
<SELECT style="width:150px;font-family:Verdana;font-size : 9pt" NAME="city" size="1">
<option value=""><b>Select City</b>
</select> -->
</td>
</tr>
<tr>
<td>Area</td>
<td colspan="2"><input type="text" name="area" size=5 maxlength=3>
<!--<SELECT style="width:200px;font-family:Verdana;font-size : 9pt" NAME="town" size="1">
<option value="">Select Area
</select>
</td>-->
</tr>
<tr><!--
<td>Blood Group</td>
<td colspan="2">
<input type="text" name="bloodgroup" size=5 maxlength=3>
<SELECT style="width:75px;font-family:Verdana;font-size : 9pt" NAME="bloodgroup" size="1">
<option value="">Select
<option value="1" > A1+
<option value="2" > A1-
<option value="3" > A2+
<option value="4" > A2-
<option value="5" > B+
<option value="6" > B-
<option value="7" > A1B+
<option value="8" > A1B-
<option value="9" > A2B+
<option value="10" > A2B-
<option value="11" > AB+
<option value="12" > AB-
<option value="13" > O+
<option value="14" > O-
<option value="15" > A+
<option value="16" > A-
</select> -->
</td>
</tr>
<center>
<tr>
<td><br>
<input type="submit" value="submit" name="btnSubmit">
<input type="reset" value="Reset" name="btnReset">
</td>
</tr>
</center>
</table>
</form>
</center>
</body>
</html>
//web-inf
<web-app>
<
servlet>
<servlet-name>actionservlet</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>actionservlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
//struts-config.xml
<struts-config>
<form-beans>
<form-bean name="lf" type="com.arvensys.work.LoginForm"/>
</form-beans>
<action-mappings>
<action path="/login" type="com.arvensys.work.LoginServlet" name="lf" scope="session" validate="true" input="/login.html">
<forward name="success" path="/response.jsp"/>
<forward name="failure" path="/error.jsp"/>
</action>
</action-mappings>
<message-resources parameter="Application-Resources"/>
</struts-config>
//loginform.java This is class is for form bean
package com.arvensys.work;
import org.apache.struts.action.*;
import javax.servlet.http.*;
/**
* @version jdk 1.5 03 April 2008
* @author Kiran Kumar
* This class is for
*/
public class LoginForm extends ActionForm {
String name,username,password,repassword,gender,email,state,city,area,bloodgroup;
int dob,weight,mobileno;
/** Here all setter and getter methods in registration form */
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public void setUserName(String username) {
this.username=username;
}
public String getUserName() {
return username;
}
public void setPassword(String password) {
this.password =password;
}
public String getPassword() {
return password;
}
/*public void setRePassword(String password) {
this.repassword =repassword;
}
public String getRePassword() {
return repassword;
}
*/
public void setGender(String gender) {
this.gender=gender;
}
public String getGender() {
return gender;
}
public void setDoB(int dob) {
this.dob =dob;
}
public int getDoB() {
return dob;
}
public void setWeight(int weight) {
this.weight=weight;
}
public int getWeight(){
return weight;
}
public void setEmail(String email) {
this.email=email;
}
public String getEmail(){
return email;
}
public void setBloodGroup(String bloodgroup) {
this.bloodgroup=bloodgroup;
}
public String getBloodGroup() {
return bloodgroup;
}
public void setState(String state) {
this.state=state;
}
public String getState(){
return state;
}
public void setCity(String city) {
this.city=city;
}
public String getCity() {
return city;
}
public void setArea(String area) {
this.area=area;
}
public String getArea() {
return area;
}
public void setMobileNo(int mobileno) {
this.mobileno=mobileno;
}
public int getMobileNo() {
return mobileno;
}
/**
* Validate the properties that have been sent from the HTTP request,
* and return an ActionErrors object that encapsulates any
* validation errors that have been found. If no errors are found, return
* an empty ActionErrors object.
*/
// This method validates register form
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
System.out.println("inside ActionErrors");
ActionErrors ae=new ActionErrors();
// Here to perform validators
/*
If this method returns 'null' or empty ActionErrors object then RequestProcessor considers that the validation is successful if not validation is failed
*/
if((username==null) || (username.equals("")))
ae.add("registerform",new ActionError("username.empty"));
System.out.println("after username validations");
if((password==null) || (password.equals("")) || (repassword==null) || (repassword.equals(""))) {
ae.add("registerform", new ActionError("password.empty"));
System.out.println("after password validations");
} else if(!password.equals(repassword)){
ae.add("registerform",new ActionError("repass.notequal"));
System.out.println("after repassword validations");
}
System.out.println("before return");
System.out.println(ae);
return ae;
}// validate method
public void reset(ActionMapping mapping, HttpServletRequest request) {
/** Because this ActionForm should be request scope, do nothing here because
* the fields will be reset when a new instance is created. We could
* have just not overrode the parent reset() method, but did so just
* to provide an example of the reset() method signature.
*/
System.out.println("inside reset");
}// reset method
}// LoginForm
// LoginAction servlet
package com.arvensys.work;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class LoginServlet extends Action {
public ActionForward execute(ActionMapping am,ActionForm af,
HttpServletRequest request,HttpServletResponse response) throws Exception {
System.out.println("before casting");
LoginForm lf=(LoginForm)af;
System.out.println("after casting");
try{
System.out.println("in try");
String userName = "root";
String password = "arvensys";
String url = "jdbc:mysql://localhost:3306/bloodbank";
Class.forName ("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection (url,userName,password );
System.out.println ("Database connection established");
String sqlstatement="insert into donortable values(?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sqlstatement);
ps.setString(1,lf.getName());
ps.setString(2,lf.getUserName());
ps.setString(3,lf.getPassword());
ps.setString(4,lf.getGender());
ps.setString(5,lf.getBloodGroup());
ps.setInt(6,lf.getWeight());
ps.setInt(7,lf.getDoB());
ps.setInt(8,lf.getMobileNo());
ps.setString(9,lf.getEmail());
ps.setString(10,lf.getArea());
ps.setString(11,lf.getCity());
ps.setString(12,lf.getState());
if(ps.executeUpdate()==1)
return am.findForward("success");
} catch (Exception e) {
e.printStackTrace();
System.out.println ("Cannot connect to database server");
}// catch
returnam.findForward("failure");
}
}
I created
struts folders no errors while compiling when I run this appplication on
tomcat 5.0 server its again showing errors. please help me
Thanks in advance.