Guest User

Untitled

a guest
Apr 25th, 2019
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. index .html
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <title>Login form</title>
  7. </head>
  8. <body>
  9. <h1>Google Form</h1>
  10. <a href="Login.html">Login</a>
  11. <a href="LogOut">Logout</a>
  12.  
  13.  
  14. </body>
  15. </html>
  16.  
  17. login.html
  18.  
  19. <!DOCTYPE html>
  20.  
  21. <html>
  22. <head>
  23.  
  24. <meta charset="UTF-8">
  25. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  26. </head>
  27. <body>
  28.  
  29.  
  30. <h1>LOGIN</h1>
  31.  
  32. <form action="MySQLConnect" method="post" >
  33. Username :<input type="text" name="user" /><br/><br/>
  34. Password :<input type="text" name="pass" /><br/><br/>
  35. <input type="submit" value="Login" />
  36. <a href="Signup.html">Sign Up</a>
  37. </form>
  38.  
  39.  
  40. </body>
  41. </html>
  42.  
  43.  
  44.  
  45. logout.html
  46.  
  47.  
  48. import java.io.IOException;
  49. import java.io.PrintWriter;
  50.  
  51. import javax.servlet.ServletException;
  52. import javax.servlet.http.HttpServlet;
  53. import javax.servlet.http.HttpServletRequest;
  54. import javax.servlet.http.HttpServletResponse;
  55. import javax.servlet.http.HttpSession;
  56. public class LogOut extends HttpServlet {
  57. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  58. response.setContentType("text/html");
  59. PrintWriter out=response.getWriter();
  60.  
  61. HttpSession session=request.getSession();
  62. session.invalidate();
  63.  
  64. out.print("You are successfully logged out!");
  65. request.getRequestDispatcher("index.html").include(request, response);
  66.  
  67. out.close();
  68. }
  69.  
  70.  
  71.  
  72. }
  73.  
  74. reg1.java
  75.  
  76. import java.io.*;
  77.  
  78. import javax.servlet.*;
  79.  
  80. import javax.servlet.http.*;
  81.  
  82. import java.sql.*;
  83.  
  84. public class Reg1 extends HttpServlet {
  85.  
  86. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  87.  
  88. throws ServletException, IOException {
  89.  
  90. response.setContentType("text/html");
  91.  
  92. PrintWriter out = response.getWriter();
  93.  
  94. String n = request.getParameter("fname");
  95.  
  96. String p = request.getParameter("lname");
  97.  
  98. String e = request.getParameter("user");
  99.  
  100. String c = request.getParameter("pass");
  101.  
  102. try {
  103.  
  104. Class.forName("com.mysql.jdbc.Driver");
  105. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/set5", "root", "");
  106.  
  107. PreparedStatement stmt = con.prepareStatement("insert into login values(?,?,?,?)");
  108.  
  109. stmt.setString(1, n);
  110.  
  111. stmt.setString(2, p);
  112.  
  113. stmt.setString(3, e);
  114.  
  115. stmt.setString(4, c);
  116.  
  117. int i = stmt.executeUpdate();
  118.  
  119. if (i > 0) {
  120.  
  121. out.println("You are successfully registered.....");
  122.  
  123. out.println("<a href=index.html>Login</a>");
  124.  
  125. }
  126.  
  127. } catch (Exception ey) {
  128.  
  129. System.out.println(ey);
  130.  
  131. }
  132.  
  133. out.close();
  134.  
  135. }
  136.  
  137. }
  138.  
  139. signup.html
  140.  
  141. <!DOCTYPE html>
  142.  
  143. <html>
  144. <head>
  145. <meta charset="UTF-8">
  146. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  147. </head>
  148. <body>
  149. <h1>REGISTRATION</h1>
  150.  
  151. <form action="Reg1" method="post">
  152.  
  153. First Name :<input type="text" name="fname"><br><br>
  154. Last Name :<input type="text" name="lname"><br><br>
  155. User Name :<input type="text" name="user"><br><br>
  156. Password :<input type="password" name="pass"><br><br>
  157.  
  158. <input type="submit" value="Submit"><br>
  159.  
  160. </form>
  161.  
  162.  
  163. </body>
  164. </html>
Add Comment
Please, Sign In to add comment