<!doctype html>
<body>
<form action="servlet/Register" method="post">
<fieldset style="width:20%; background-color:#ccffeb">
<h2 align="center">Registration form</h2><hr>
<table>
<tr>
<td>Name</td>
<td><input type="text" name="userName" required /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="userPass" required /></td>
</tr>
<tr>
<td>Email Id</td>
<td><input type="text" name="userEmail" required /></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="text" name="userMobile" required/></td>
</tr>
<tr>
<td>Date of Birth</td>
<td><input type="date" name="userDOB" required/></td>
</tr>
<tr>
<td>Gender</td>
<td><input type="radio" name="gender" value="male" checked> Male
<input type="radio" name="gender" value="female"> Female </td></tr>
<tr>
<td>Country</td>
<td><select name="userCountry" style="width:130px">
<option>Select a country</option>
<option>India</option>
<option>America</option>
<option>England</option>
<option>other</option></select>
</td>
</tr>
<tr>
<td><input type="reset" value="Reset"/></td>
<td><input type="submit" value="Register"/></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>
import java.io.*;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class Register extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name = request.getParameter("userName");
String pwd = request.getParameter("userPass");
String email = request.getParameter("userEmail");
int mobile = Integer.parseInt(request.getParameter("userMobile"));
String dob = request.getParameter("userDOB");
String gender = request.getParameter("gender");
String country =request.getParameter("userCountry");
try
{
//load the driver
Class.forName("oracle.jdbc.driver.OracleDriver");
//create connection object
Connection con=DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","local","test");
// create the prepared statement object
PreparedStatement ps=con.prepareStatement("insert into registration values(?,?,?,?,?,?,?)");
ps.setString(1,name);
ps.setString(2,pwd);
ps.setString(3,email);
ps.setInt(4, mobile);
ps.setString(5,dob);
ps.setString(6,gender);
ps.setString(7,country);
int i = ps.executeUpdate();
if(i>0)
out.print("You are successfully registered...");
}
catch (Exception ex)
{
ex.printStackTrace();
}
out.close();
}
}
<web-app>
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/servlet/Register</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>register.html</welcome-file>
</welcome-file-list>
</web-app>