Guest User

Untitled

a guest
May 11th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1.  
  2. import java.sql.ResultSet;
  3. import eskuel.CMI_SQL;
  4. import java.io.IOException;
  5. import java.io.PrintWriter;
  6. import java.sql.SQLException;
  7. import javax.servlet.*;
  8. import javax.servlet.http.*;
  9.  
  10. /**
  11. *
  12. * @author Ilse Beijk 0814147
  13. */
  14. public class LoginAuth extends HttpServlet {
  15.  
  16. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  17. throws ServletException, IOException {
  18. response.setContentType("text/html;charset=UTF-8");
  19. PrintWriter out = response.getWriter();
  20. try {
  21.  
  22. CMI_SQL sql = new CMI_SQL("jdbc:mysql://mysql.cmi-hro.nl:3306/cmi0814619", "cmi0814619", "-----");
  23.  
  24. String username = request.getParameter("user");
  25. String password = request.getParameter("pass");
  26. String passWord;
  27. String userName;
  28. String accommodatie, land, accomodatie_nr;
  29.  
  30. String query = "SELECT reserverings_nr, achternaam FROM klanten WHERE achternaam ='" + username + "' AND reserverings_nr ='" + password + "'";
  31. ResultSet resultaat = sql.selectieQuery(query);
  32.  
  33. try {
  34. while (resultaat.next()) {
  35. passWord = resultaat.getString("reserverings_nr");
  36. userName = resultaat.getString("achternaam");
  37.  
  38. if (userName.equals(username) && passWord.equals(password)) {
  39. request.getSession().setAttribute("authorized", "yes");
  40. request.getSession().setAttribute("username", userName);
  41. request.getSession().setAttribute("password", passWord);
  42. String nextJSP = "/enq_p1.jsp";
  43. RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP);
  44. dispatcher.forward(request, response);
  45.  
  46. }
  47. }
  48. } catch (SQLException e_sql) {
  49. }
  50.  
  51. out.println("<html><body>");
  52. out.println("Foutieve inlog, probeer opnieuw <a href=/index.jsp>in te loggen</a>");
  53. out.println("</body></html>");
  54.  
  55.  
  56.  
  57.  
  58. } finally {
  59. out.close();
  60. }
  61.  
  62. }
  63.  
  64. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  65. /**
  66. * Handles the HTTP <code>GET</code> method.
  67. * @param request servlet request
  68. * @param response servlet response
  69. */
  70. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  71. throws ServletException, IOException {
  72. processRequest(request, response);
  73. }
  74.  
  75. /**
  76. * Handles the HTTP <code>POST</code> method.
  77. * @param request servlet request
  78. * @param response servlet response
  79. */
  80. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  81. throws ServletException, IOException {
  82. processRequest(request, response);
  83. }
  84.  
  85. /**
  86. * Returns a short description of the servlet.
  87. */
  88. public String getServletInfo() {
  89. return "Short description";
  90. }
  91. // </editor-fold>
  92. }
Add Comment
Please, Sign In to add comment