Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. public class NewServlet1 extends HttpServlet {
  2.  
  3. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  4. throws ServletException, IOException {
  5. response.setContentType("text/html;charset=UTF-8");
  6. PrintWriter out = response.getWriter();
  7.  
  8. String name=request.getParameter("username");
  9. String abc=request.getParameter("password");
  10.  
  11. aaaa c1=new aaaa();
  12.  
  13. try{
  14.  
  15. String Sql="insert into login(username,password) values('"+name+"','"+abc+"')";
  16.  
  17. c1.st.executeUpdate(Sql);
  18. }
  19. catch(SQLException ex)
  20. {
  21.  
  22. out.println(ex);
  23.  
  24. }
  25.  
  26. try {
  27. /*
  28. * TODO output your page here. You may use following sample code.
  29. */
  30. out.println("<html>");
  31. out.println("<head>");
  32. out.println("<title>Servlet NewServlet1</title>");
  33. out.println("</head>");
  34. out.println("<body>");
  35. out.println("<h1>Servlet NewServlet1 at " + request.getContextPath() + "</h1>");
  36. out.println("</body>");
  37. out.println("</html>");
  38. }
  39. finally {
  40. out.close();
  41. }
  42. }
  43.  
  44. <html>
  45. <head>
  46.  
  47. </head>
  48. <body>
  49. <form method="GET " action="NewServlet1" autocomplete="on">
  50. <h1>Log in</h1>
  51. <p>
  52. <label for="username" class="uname" data-icon="u" >Username:</label>
  53. <input id="username" name="username" required="required" type="text" placeholder="Username"/>
  54. <label for="password" class="youpasswd" data-icon="p">Password:</label>
  55. <input id="password" name="password" required="required" type="password" placeholder="Password" />
  56. </p>
  57. <p class="keeplogin">
  58. <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
  59. <label for="loginkeeping">Keep me logged in</label>
  60. </p>
  61. <p class="login button">
  62.  
  63. <input type="submit" value="Login" />
  64.  
  65. </p>
  66.  
  67. <input type="radio" name="gender" value="Teach" checked/> Teacher
  68. <input type="radio" name="gender" value="Student"/>Student
  69.  
  70. </form>
  71. </body>
  72. </html>
  73.  
  74. public class aaaa {
  75.  
  76. Connection c1 = null;
  77. Statement st = null;
  78. ResultSet rs = null;
  79. aaaa(){
  80. try {
  81. Class.forName("com.mysql.jdbc.Driver");
  82. c1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/teacher","root", "abcde");
  83.  
  84. }
  85. catch (Exception cnfe) {
  86. System.out.println("Couldn't find the driver!");
  87. System.out.println("Couldn't connect: print out a stack trace and exit.");
  88. System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
  89. }
  90. try {
  91. st = (Statement) c1.createStatement();
  92. System.out.println("Statement Created Successfully");
  93. } catch (SQLException se) {
  94. System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected.");
  95. se.printStackTrace();
  96. }
  97. if (c1 != null) {
  98. System. out.println("Hooray! We connected to the database!");
  99. } else {
  100. System.out.println("We should never get here.");
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement