Html -> Servlet Page-> JDBC

Write a Servlet Program that verifys and updates the data in the use html as front end?

 

 CREATE TABLE  "REGISTERUSER" 
   (    "NAME" VARCHAR2(4000), 
    "PASS" VARCHAR2(4000), 
    "EMAIL" VARCHAR2(4000), 
    "COUNTRY" VARCHAR2(4000)
   ) 

 

register.html  

  <html> 
    <body> 
    <form action="Register" method="post"> 
     
    Name:<input type="text" name="userName"/><br/><br/> 
    Password:<input type="password" name="userPass"/><br/><br/> 
    Email Id:<input type="text" name="userEmail"/><br/><br/> 
    Country: 
    <select name="userCountry"> 
    <option>India</option> 
    <option>China</option> 
    <option>other</option> 
    </select> 
     
    <br/><br/> 
    <input type="submit" value="register"/> 
     
    </form> 
    </body> 
    </html>  


 Register.java(servlet Page)

     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 n=request.getParameter("userName"); 
    String p=request.getParameter("userPass"); 
    String e=request.getParameter("userEmail"); 
    String c=request.getParameter("userCountry"); 
             
    try{ 
    Class.forName("org.apache.derby.jdbc.ClientDriver"); 
    Connection con=DriverManager.getConnection( 
    "jdbc:derby://localhost:1527/kbn","kbn","kbn"); 
     
    PreparedStatement ps=con.prepareStatement( 
    "insert into registeruser values(?,?,?,?)"); 
     
    ps.setString(1,n); 
    ps.setString(2,p); 
    ps.setString(3,e); 
    ps.setString(4,c); 
             
    int i=ps.executeUpdate(); 
    if(i>0) 
    out.print("You are successfully registered..."); 
         
             
    }

catch (Exception e2) 
{
System.out.println(e2);

             
    out.close(); 
    } 
     
    } 



web.xml

 <welcome-file-list> 
    <welcome-file>register.html</welcome-file> 
</welcome-file-list> 




 

Comments

Popular posts from this blog

Java Beans Program

MACHINE LEARNING IN REAL WORLD

MACHINE LEARNING INTRODUCTION