Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- 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.
- -->
- <html>
- <head>
- <title>TODO supply a title</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <div>
- <form action="Servlettt" method="POST">
- <table>
- <tr>
- <td>Username:</td>
- <td><input type="text" name="user"></td>
- </tr>
- <tr>
- <td>Password:</td>
- <td><input type="text" name="pass"></td>
- </tr>
- <tr>
- <td><input type="submit" name="Submit" value="Submit"></td>
- <td><a href="index2.html">Register</a></td>
- </tr>
- </table>
- </form>
- </div>
- </body>
- </html>
- import java.sql.*;
- import org.jboss.logging.Logger;
- /*
- * 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.
- */
- /**
- *
- * @author JNEC-08
- */
- public class DBConnection {
- Connection conn;
- Statement stmt;
- ResultSet rs;
- String query;
- public DBConnection()
- {
- try{
- String dburl="jdbc:mysql://localhost:3306/Test73";
- Class.forName("com.mysql.jdbc.Driver");
- conn=DriverManager.getConnection(dburl,"root","mysql");
- stmt=conn.createStatement();
- }
- catch(ClassNotFoundException ce)
- {
- Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, ce);
- }
- catch(SQLException se)
- {
- Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, se);
- }
- }
- public boolean check(String u,String p)
- {
- try{
- query="select * from register_info where user='"+u+"' and password='"+p+"';";
- rs=stmt.executeQuery(query);
- while(rs.next())
- {
- if(u==rs.getString(0) && p==rs.getString(1))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- catch(SQLException se)
- {
- Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, se);
- }
- return false;
- }
- public int insert(String u,String p,String g,String e,String b)
- {
- try{
- query="insert into register_info values('"+u+"','"+p+"','"+g+"','"+e+"','"+b+"');";
- int count=stmt.executeUpdate(query);
- return count;
- }
- catch(SQLException se)
- {
- Logger.getLogger(DBConnection.class.getName()).log(Logger.Level.FATAL, null, se);
- }
- return 0;
- }
- }
- /*
- * 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 javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- *
- * @author JNEC-08
- */
- public class Register extends HttpServlet {
- /**
- * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- /* TODO output your page here. You may use following sample code. */
- out.println("<!DOCTYPE html>");
- out.println("<html>");
- out.println("<head>");
- out.println("<title>Servlet Register</title>");
- out.println("</head>");
- out.println("<body>");
- String u=request.getParameter("user");
- String p=request.getParameter("pass");
- String g=request.getParameter("gen");
- String e=request.getParameter("email");
- String b=request.getParameter("branch");
- DBConnection db=new DBConnection();
- int count=db.insert(u, p, g, e, b);
- if(count>0)
- {
- out.println("record inserted....");
- }
- else
- {
- out.println("record not inserted....");
- }
- out.println("<h1>Servlet Register at " + request.getContextPath() + "</h1>");
- out.println("</body>");
- out.println("</html>");
- }
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</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
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /**
- * 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
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- }
- /*
- * 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 javax.servlet.RequestDispatcher;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- /**
- *
- * @author JNEC-08
- */
- public class Servlettt extends HttpServlet {
- /**
- * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- /* TODO output your page here. You may use following sample code. */
- out.println("<!DOCTYPE html>");
- out.println("<html>");
- out.println("<head>");
- out.println("<title>Servlet Servlettt</title>");
- out.println("</head>");
- out.println("<body>");
- DBConnection db=new DBConnection();
- String u=request.getParameter("user");
- String p=request.getParameter("pass");
- Boolean bb=db.check(u,p);
- if(bb)
- {
- out.println("Login Successfull.....");
- }
- else
- {
- out.println("Login not Successfull.....");
- RequestDispatcher rd=request.getRequestDispatcher("index.html");
- rd.include(request,response);
- }
- out.println("<h1>Servlet Servlettt at " + request.getContextPath() + "</h1>");
- out.println("</body>");
- out.println("</html>");
- }
- }
- // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
- /**
- * Handles the HTTP <code>GET</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
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /**
- * 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
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }// </editor-fold>
- }
- <!DOCTYPE html>
- <!--
- 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.
- -->
- <html>
- <head>
- <title>TODO supply a title</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <div>
- <form action="Register" method="POST">
- <table>
- <tr>
- <td>Username:</td>
- <td><input type="text" name="user"></td>
- </tr>
- <tr>
- <td>Password:</td>
- <td><input type="text" name="pass"></td>
- </tr>
- <tr>
- <td>Gender:</td>
- <td><input type="text" name="gen"></td>
- </tr>
- <tr>
- <td>Email:</td>
- <td><input type="text" name="email"></td>
- </tr>
- <tr>
- <td>Branch:</td>
- <td><input type="text" name="branch"></td>
- </tr>
- <tr>
- <td><input type="Submit" name="Submit" value="Submit"></td>
- </tr>
- </table>
- </form></div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment