Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NewServlet1 extends HttpServlet {
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- PrintWriter out = response.getWriter();
- String name=request.getParameter("username");
- String abc=request.getParameter("password");
- aaaa c1=new aaaa();
- try{
- String Sql="insert into login(username,password) values('"+name+"','"+abc+"')";
- c1.st.executeUpdate(Sql);
- }
- catch(SQLException ex)
- {
- out.println(ex);
- }
- try {
- /*
- * TODO output your page here. You may use following sample code.
- */
- out.println("<html>");
- out.println("<head>");
- out.println("<title>Servlet NewServlet1</title>");
- out.println("</head>");
- out.println("<body>");
- out.println("<h1>Servlet NewServlet1 at " + request.getContextPath() + "</h1>");
- out.println("</body>");
- out.println("</html>");
- }
- finally {
- out.close();
- }
- }
- <html>
- <head>
- </head>
- <body>
- <form method="GET " action="NewServlet1" autocomplete="on">
- <h1>Log in</h1>
- <p>
- <label for="username" class="uname" data-icon="u" >Username:</label>
- <input id="username" name="username" required="required" type="text" placeholder="Username"/>
- <label for="password" class="youpasswd" data-icon="p">Password:</label>
- <input id="password" name="password" required="required" type="password" placeholder="Password" />
- </p>
- <p class="keeplogin">
- <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
- <label for="loginkeeping">Keep me logged in</label>
- </p>
- <p class="login button">
- <input type="submit" value="Login" />
- </p>
- <input type="radio" name="gender" value="Teach" checked/> Teacher
- <input type="radio" name="gender" value="Student"/>Student
- </form>
- </body>
- </html>
- public class aaaa {
- Connection c1 = null;
- Statement st = null;
- ResultSet rs = null;
- aaaa(){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- c1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/teacher","root", "abcde");
- }
- catch (Exception cnfe) {
- System.out.println("Couldn't find the driver!");
- System.out.println("Couldn't connect: print out a stack trace and exit.");
- System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
- }
- try {
- st = (Statement) c1.createStatement();
- System.out.println("Statement Created Successfully");
- } catch (SQLException se) {
- System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
- se.printStackTrace();
- }
- if (c1 != null) {
- System. out.println("Hooray! We connected to the database!");
- } else {
- System.out.println("We should never get here.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement