import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class RegisterServlet extends GenericServlet
{
Connection con;
Statement st;

public void init(ServletConfig sc)
{
try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void service(ServletRequest req,ServletResponse res)
{

try
{
int r=Integer.parseInt(req.getParameter("t1"));
String n=req.getParameter("t2");
String b=req.getParameter("t3");
st=con.createStatement();
int a=st.executeUpdate("insert into student values("+r+",' "+n+" ',' "+b+" ')");
PrintWriter out=res.getWriter();
out.println(a+ " Record inserted");
}
catch(Exception e){e.printStackTrace();}

}
public void destroy()
{
try{ st.close(); con.close();}
catch(Exception e)
{
e.printStackTrace();
}
}

}

index.html:-
html
body
form action="./register"
rnoinput type="text" name="t1"/br/
nameinput type="text" name="t2"/br/
branchinput type="text" name="t3"/br/
input type="submit" value="REGISTER"/
/form
/body
/html

web.xml:-
web-app
servlet
servlet-nameex4/servlet-name
servlet-classRegisterServlet/servlet-class
/servlet
servlet-mapping
servlet-nameex4/servlet-name
url-pattern/register/url-pattern
/servlet-mapping
/web-app