Guest User

Untitled

a guest
Jun 1st, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1.  
  2. import java.io.*;
  3. import java.sql.*;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6.  
  7. public class LoginAuth extends HttpServlet {
  8.  
  9. private ServletConfig config;
  10.  
  11. public void init(ServletConfig config)
  12. throws ServletException {
  13. this.config = config;
  14. }
  15.  
  16. public void doPost(HttpServletRequest request, HttpServletResponse response)
  17. throws ServletException, IOException {
  18.  
  19. HttpSession session = request.getSession(true);
  20.  
  21. PrintWriter out = response.getWriter();
  22.  
  23. String connectionURL = "jdbc:mysql://mysql.cmi-hro.nl:3306/cmi0814619";
  24. Connection connection = null;
  25. ResultSet rs;
  26. String databaseUsername;
  27. String databasePassword;
  28. String username = request.getParameter("user");
  29. String password = request.getParameter("pass");
  30. response.setContentType("text/html");
  31. try {
  32. // Load the database driver
  33. Class.forName("com.mysql.jdbc.Driver");
  34. // Get a Connection to the database
  35. connection = DriverManager.getConnection(connectionURL, "cmi0814619", "0000000");
  36. //Add the data into the database
  37. String sql = "select achternaam,reserverings_nr from cmi0814619.klanten";
  38. Statement s = connection.createStatement();
  39. s.executeQuery(sql);
  40. rs = s.getResultSet();
  41. while (rs.next()) {
  42. databaseUsername = rs.getString("achternaam");
  43. databasePassword = rs.getString("reserverings_nr");
  44.  
  45. if (databaseUsername.equals(username) && databasePassword.equals(password)){
  46. session.setAttribute("userName", username);
  47. session.setAttribute("passwrd", password);
  48.  
  49. String nextJSP = "enq_p1.jsp";
  50. response.sendRedirect(nextJSP);
  51. }
  52. rs.close();
  53. s.close();
  54. }
  55. } catch (Exception e) {
  56. System.out.println("Exception is ;" + e);
  57. }
  58. String nextJSP = "fout_ingelogd.jsp";
  59. response.sendRedirect(nextJSP);
  60. }
  61. }
Add Comment
Please, Sign In to add comment