Registration form
Published: 2023-03-14 02:02:23

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author A
 */
public class login extends HttpServlet {

   
       

   
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       response.setContentType("text/html;Charset=UTF-8");
       PrintWriter out = response.getWriter();
        
         out.println("<form><p>id : <input type='text' name='id'></p>"
                 + "<p> name: <input type='text' name='name'></p>"
                 + "<p>age:<input type='text' name='age'></p>"
                 + "<p>phone no:<input type='text' name='mno'></p>"
                 + "<p>Gender:</p>" +
" <input type='radio' id='male' name='male' value='male'>"+
" <label for='male'>male</label><br>" +
" <input type='radio' id='female' name='female' value='female'>" +
" <label for='female'>female</label><br>" +
" <input type='radio' id='other' name='other' value='other'>" +
" <label for='other'>other</label>");
         out.println("<form><input type='submit' value='Add' name='add'>");
         out.println("<form><input type='submit' value='Update' name='update'>");
         out.println("<form><input type='submit' value='Delete' name='delete'>");
         String id=request.getParameter("id");
         String name=request.getParameter("name");
         String age=request.getParameter("age");
         String mno=request.getParameter("mno");
         String gender=request.getParameter("gender");
          if(request.getParameter("add")!=null){
         try{
             Class.forName("com.mysql.jdbc.Driver");
             Connection Con =  DriverManager.getConnection("jdbc:mysql://localhost:3306/javapoint","root","");
               Statement stmt=Con.createStatement();
               stmt.executeUpdate("insert into form values('"+id+"','"+age+"','"+name+"')");
               out.println("enter successfully");
               
               
         stmt.close();
         Con.close();
          
       } catch (ClassNotFoundException ex) {
            Logger.getLogger(form.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(form.class.getName()).log(Level.SEVERE, null, ex);
        }

       }
    

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
   

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
   

}