Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3.  
  4. public class Validate
  5. {
  6.  
  7. public static boolean checkUser(String email,String pass)
  8.  
  9. {
  10. boolean st =false;
  11. try{
  12.  
  13. //loading drivers for mysql
  14. Class.forName("com.mysql.jdbc.Driver");
  15.  
  16. //creating connection with the database
  17. Connection con=DriverManager.getConnection
  18. ("jdbc:mysql:/ /localhost:3306/test","root","studytonight");
  19. PreparedStatement ps =con.prepareStatement
  20. ("select * from register where email=? and pass=?");
  21. ps.setString(1, email);
  22. ps.setString(2, pass);
  23. ResultSet rs =ps.executeQuery();
  24. st = rs.next();
  25.  
  26. }catch(Exception e)
  27. {
  28. e.printStackTrace();
  29. }
  30. return st;
  31. }
  32. }
  33.  
  34. import java.io.*;
  35. import javax.servlet.*;
  36. import javax.servlet.http.*;
  37. import java.sql.*;
  38.  
  39. public class Login extends HttpServlet
  40. {
  41.  
  42. protected void doPost(HttpServletRequest request, HttpServletResponse
  43. response)
  44. throws ServletException, IOException {
  45. response.setContentType("text/html;charset=UTF-8");
  46. PrintWriter out = response.getWriter();
  47.  
  48. String email = request.getParameter("email");
  49. String pass = request.getParameter("pass");
  50.  
  51. if(**Validate**.checkUser(email, pass))
  52. {
  53. RequestDispatcher rs = request.getRequestDispatcher("Welcome");
  54. rs.forward(request, response);
  55. }
  56. else
  57. {
  58. out.println("Username or Password incorrect");
  59. RequestDispatcher rs = request.getRequestDispatcher("index.html");
  60. rs.include(request, response);
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement