Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. a<%--
  2. Document : Loginconfirmation
  3. Created on : Apr 28, 2017, 6:04:57 PM
  4. Author : Ryuji
  5. --%>
  6.  
  7. <%@page import="java.sql.ResultSet"%>
  8. <%@page import="java.sql.Statement"%>
  9. <%@page import="java.sql.DriverManager"%>
  10. <%@page import="java.sql.Connection"%>
  11. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  12. <!DOCTYPE html>
  13. <html>
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  16. <title>JSP Page</title>
  17.  
  18. <%
  19. boolean checkLogin = false;
  20. String status = "";
  21.  
  22. String UserID = request.getParameter("UserID");
  23. String Password = request.getParameter("Password");
  24.  
  25.  
  26. Connection connection = null;
  27.  
  28. try {
  29.  
  30. Class.forName("org.gjt.mm.mysql.Driver");
  31. String url = "jdbc:mysql://localhost/dbsterling";
  32. String user = "root";
  33. String pwd = "";
  34. connection = DriverManager.getConnection(url, user, pwd);
  35. Statement statement = connection.createStatement();
  36. String querySelect = "select * from sterling_login, sterling_customer, sterling_employee where sterling_login.UserID = sterling_customer.UserID && sterling_login.UserID = sterling_employee.UserID && sterling_login.UserID = '" + UserID + "'";
  37.  
  38. ResultSet rows = statement.executeQuery(querySelect);
  39.  
  40. while (rows.next()) {
  41. if((rows.getString("sterling_customer.UserID") == UserID) && (rows.getString("sterling_login.Password") == Password)) {
  42. checkLogin = true;
  43. status = "Customer";
  44. }
  45. else if((rows.getString("sterling_employee.UserID") == UserID) && (rows.getString("sterling_employee.Designation") == "M") && (rows.getString("sterling_login.Password") == Password)) {
  46. checkLogin = true;
  47. status = "Manager";
  48. }
  49. else if((rows.getString("sterling_employee.UserID") == UserID) && (rows.getString("sterling_employee.Designation") == "C") && (rows.getString("sterling_login.Password") == Password)) {
  50. checkLogin = true;
  51. status = "Clerk";
  52. }
  53. else if((rows.getString("sterling_employee.UserID") == UserID) && (rows.getString("sterling_employee.Designation") == "D") && (rows.getString("sterling_login.Password") == Password)) {
  54. checkLogin = true;
  55. status = "DeliveryBoy";
  56. }
  57. else
  58. out.println("<script>alert('Login credention does not exist!!! ');document.location.href='Login.jsp';</script>");
  59. }
  60.  
  61. if(checkLogin = true) {
  62. session.setAttribute("UserID", UserID);
  63. session.setAttribute("Status", status);
  64. response.sendRedirect("home.html");
  65.  
  66. }
  67. else
  68. out.println("<script>alert('Login!!! ');document.location.href='Login.jsp';</script>");
  69.  
  70. }
  71.  
  72. catch (Exception e) {
  73. out.println("Error" + e);
  74. System.out.println("Error" + e);
  75. //It is a good practice to use System.out.println()
  76. //for printing the error messages in the server console
  77. }
  78.  
  79. finally {
  80. if (null != connection) {
  81. connection.close();
  82. }
  83. }
  84.  
  85. %>
  86.  
  87. </head>
  88. <body>
  89. <h1>Hello World!</h1>
  90. </body>
  91. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement