SHARE
TWEET

Untitled

a guest Mar 20th, 2016 28 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8.     <head>
  9.         <title>TODO supply a title</title>
  10.         <meta charset="UTF-8">
  11.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  12.     </head>
  13.     <body>
  14.         <div>
  15.         <form action="Servlettt" method="POST">
  16.         <table>
  17.             <tr>
  18.                 <td>Username:</td>
  19.                 <td><input type="text" name="user"></td>
  20.             </tr>
  21.             <tr>    
  22.                 <td>Password:</td>
  23.                 <td><input type="text" name="pass"></td>
  24.             </tr>
  25.             <tr>
  26.                 <td><input type="submit" name="Submit" value="Submit"></td>
  27.                 <td><a href="index2.html">Register</a></td>
  28.             </tr>
  29.         </table>
  30.         </form>
  31.         </div>
  32.     </body>
  33. </html>
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. import java.sql.*;
  43. import org.jboss.logging.Logger;
  44. /*
  45.  * To change this license header, choose License Headers in Project Properties.
  46.  * To change this template file, choose Tools | Templates
  47.  * and open the template in the editor.
  48.  */
  49.  
  50. /**
  51.  *
  52.  * @author JNEC-08
  53.  */
  54. public class DBConnection {
  55. Connection conn;
  56. Statement stmt;
  57. ResultSet rs;
  58. String query;
  59.  
  60.     public DBConnection()
  61.     {
  62.         try{
  63.             String dburl="jdbc:mysql://localhost:3306/Test73";
  64.             Class.forName("com.mysql.jdbc.Driver");
  65.             conn=DriverManager.getConnection(dburl,"root","mysql");
  66.             stmt=conn.createStatement();
  67.         }
  68.         catch(ClassNotFoundException ce)
  69.         {
  70.             Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, ce);
  71.         }
  72.         catch(SQLException se)
  73.         {
  74.              Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, se);
  75.         }
  76.        
  77.     }
  78.    
  79.     public boolean check(String u,String p)
  80.     {
  81.         try{
  82.             query="select * from register_info where user='"+u+"' and password='"+p+"';";
  83.             rs=stmt.executeQuery(query);
  84.             while(rs.next())
  85.             {
  86.                 if(u==rs.getString(0) && p==rs.getString(1))
  87.                 {
  88.                    
  89.                     return true;
  90.                 }
  91.                 else
  92.                 {
  93.                     return false;
  94.                 }
  95.             }
  96.         }
  97.         catch(SQLException se)
  98.         {
  99.              Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, se);
  100.         }
  101.         return false;
  102.     }
  103.    
  104.     public int insert(String u,String p,String g,String e,String b)
  105.     {
  106.         try{
  107.          query="insert into register_info values('"+u+"','"+p+"','"+g+"','"+e+"','"+b+"');";
  108.          int count=stmt.executeUpdate(query);
  109.          return count;
  110.         }
  111.         catch(SQLException se)
  112.         {
  113.             Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, se);
  114.         }
  115.         return 0;
  116.     }
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123. /*
  124.  * To change this license header, choose License Headers in Project Properties.
  125.  * To change this template file, choose Tools | Templates
  126.  * and open the template in the editor.
  127.  */
  128.  
  129. import java.io.IOException;
  130. import java.io.PrintWriter;
  131. import javax.servlet.ServletException;
  132. import javax.servlet.http.HttpServlet;
  133. import javax.servlet.http.HttpServletRequest;
  134. import javax.servlet.http.HttpServletResponse;
  135.  
  136. /**
  137.  *
  138.  * @author JNEC-08
  139.  */
  140. public class Register extends HttpServlet {
  141.  
  142.     /**
  143.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  144.      * methods.
  145.      *
  146.      * @param request servlet request
  147.      * @param response servlet response
  148.      * @throws ServletException if a servlet-specific error occurs
  149.      * @throws IOException if an I/O error occurs
  150.      */
  151.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  152.             throws ServletException, IOException {
  153.         response.setContentType("text/html;charset=UTF-8");
  154.         try (PrintWriter out = response.getWriter()) {
  155.             /* TODO output your page here. You may use following sample code. */
  156.             out.println("<!DOCTYPE html>");
  157.             out.println("<html>");
  158.             out.println("<head>");
  159.             out.println("<title>Servlet Register</title>");            
  160.             out.println("</head>");
  161.             out.println("<body>");
  162.            
  163.            
  164.             String u=request.getParameter("user");
  165.             String p=request.getParameter("pass");
  166.             String g=request.getParameter("gen");
  167.             String e=request.getParameter("email");
  168.             String b=request.getParameter("branch");
  169.            
  170.             DBConnection db=new DBConnection();
  171.             int count=db.insert(u, p, g, e, b);
  172.             if(count>0)
  173.             {
  174.             out.println("record inserted....");
  175.             }
  176.             else
  177.             {
  178.                 out.println("record not inserted....");
  179.             }
  180.            
  181.              out.println("<h1>Servlet Register at " + request.getContextPath() + "</h1>");
  182.             out.println("</body>");
  183.             out.println("</html>");
  184.         }
  185.     }
  186.  
  187.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  188.     /**
  189.      * Handles the HTTP <code>GET</code> method.
  190.      *
  191.      * @param request servlet request
  192.      * @param response servlet response
  193.      * @throws ServletException if a servlet-specific error occurs
  194.      * @throws IOException if an I/O error occurs
  195.      */
  196.     @Override
  197.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  198.             throws ServletException, IOException {
  199.         processRequest(request, response);
  200.     }
  201.  
  202.     /**
  203.      * Handles the HTTP <code>POST</code> method.
  204.      *
  205.      * @param request servlet request
  206.      * @param response servlet response
  207.      * @throws ServletException if a servlet-specific error occurs
  208.      * @throws IOException if an I/O error occurs
  209.      */
  210.     @Override
  211.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  212.             throws ServletException, IOException {
  213.         processRequest(request, response);
  214.     }
  215.  
  216.     /**
  217.      * Returns a short description of the servlet.
  218.      *
  219.      * @return a String containing servlet description
  220.      */
  221.     @Override
  222.     public String getServletInfo() {
  223.         return "Short description";
  224.     }// </editor-fold>
  225.  
  226. }
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233. /*
  234.  * To change this license header, choose License Headers in Project Properties.
  235.  * To change this template file, choose Tools | Templates
  236.  * and open the template in the editor.
  237.  */
  238.  
  239. import java.io.IOException;
  240. import java.io.PrintWriter;
  241. import javax.servlet.RequestDispatcher;
  242. import javax.servlet.ServletException;
  243. import javax.servlet.http.HttpServlet;
  244. import javax.servlet.http.HttpServletRequest;
  245. import javax.servlet.http.HttpServletResponse;
  246.  
  247. /**
  248.  *
  249.  * @author JNEC-08
  250.  */
  251. public class Servlettt extends HttpServlet {
  252.  
  253.     /**
  254.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  255.      * methods.
  256.      *
  257.      * @param request servlet request
  258.      * @param response servlet response
  259.      * @throws ServletException if a servlet-specific error occurs
  260.      * @throws IOException if an I/O error occurs
  261.      */
  262.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  263.             throws ServletException, IOException {
  264.         response.setContentType("text/html;charset=UTF-8");
  265.         try (PrintWriter out = response.getWriter()) {
  266.             /* TODO output your page here. You may use following sample code. */
  267.             out.println("<!DOCTYPE html>");
  268.             out.println("<html>");
  269.             out.println("<head>");
  270.             out.println("<title>Servlet Servlettt</title>");            
  271.             out.println("</head>");
  272.             out.println("<body>");
  273.            
  274.             DBConnection db=new DBConnection();
  275.             String u=request.getParameter("user");
  276.             String p=request.getParameter("pass");
  277.            
  278.             Boolean bb=db.check(u,p);
  279.             if(bb)
  280.             {
  281.                 out.println("Login Successfull.....");
  282.             }
  283.             else
  284.             {
  285.                 out.println("Login not Successfull.....");
  286.                 RequestDispatcher rd=request.getRequestDispatcher("index.html");
  287.                 rd.include(request,response);
  288.             }
  289.             out.println("<h1>Servlet Servlettt at " + request.getContextPath() + "</h1>");
  290.             out.println("</body>");
  291.             out.println("</html>");
  292.            
  293.            
  294.         }
  295.     }
  296.  
  297.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  298.     /**
  299.      * Handles the HTTP <code>GET</code> method.
  300.      *
  301.      * @param request servlet request
  302.      * @param response servlet response
  303.      * @throws ServletException if a servlet-specific error occurs
  304.      * @throws IOException if an I/O error occurs
  305.      */
  306.     @Override
  307.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  308.             throws ServletException, IOException {
  309.         processRequest(request, response);
  310.     }
  311.  
  312.     /**
  313.      * Handles the HTTP <code>POST</code> method.
  314.      *
  315.      * @param request servlet request
  316.      * @param response servlet response
  317.      * @throws ServletException if a servlet-specific error occurs
  318.      * @throws IOException if an I/O error occurs
  319.      */
  320.     @Override
  321.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  322.             throws ServletException, IOException {
  323.         processRequest(request, response);
  324.     }
  325.  
  326.     /**
  327.      * Returns a short description of the servlet.
  328.      *
  329.      * @return a String containing servlet description
  330.      */
  331.     @Override
  332.     public String getServletInfo() {
  333.         return "Short description";
  334.     }// </editor-fold>
  335.  
  336. }
  337.  
  338.  
  339.  
  340.  
  341.  
  342. <!DOCTYPE html>
  343. <!--
  344. To change this license header, choose License Headers in Project Properties.
  345. To change this template file, choose Tools | Templates
  346. and open the template in the editor.
  347. -->
  348. <html>
  349.     <head>
  350.         <title>TODO supply a title</title>
  351.         <meta charset="UTF-8">
  352.         <meta name="viewport" content="width=device-width, initial-scale=1.0">
  353.     </head>
  354.     <body>
  355.         <div>
  356.          <form action="Register" method="POST">
  357.         <table>
  358.             <tr>
  359.                 <td>Username:</td>
  360.                 <td><input type="text" name="user"></td>
  361.             </tr>
  362.             <tr>    
  363.                 <td>Password:</td>
  364.                 <td><input type="text" name="pass"></td>
  365.             </tr>
  366.             <tr>
  367.                 <td>Gender:</td>
  368.                 <td><input type="text" name="gen"></td>
  369.             </tr>
  370.             <tr>    
  371.                 <td>Email:</td>
  372.                 <td><input type="text" name="email"></td>
  373.             </tr>
  374.             <tr>    
  375.                 <td>Branch:</td>
  376.                 <td><input type="text" name="branch"></td>
  377.             </tr>
  378.             <tr>
  379.                 <td><input type="Submit" name="Submit" value="Submit"></td>
  380.                
  381.             </tr>
  382.         </table>
  383.         </form></div>
  384.     </body>
  385. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top