Zozwang

Untitled

May 18th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <%@ page import="java.sql.*"%>
  2. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  3. pageEncoding="UTF8"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <%
  12. String name=request.getParameter("username");
  13. String pass=request.getParameter("password");
  14.  
  15. if (name.equals("zohar") && pass.equals("123"))
  16. {
  17. session.setAttribute("EnterSite","ok");
  18. response.sendRedirect("homepage.jsp");
  19. }
  20. else if (name.equals("zohar") && pass.equals("1234"))
  21. {
  22. session.setAttribute("EnterSite","manager");
  23. response.sendRedirect("homepage.jsp");
  24. }
  25.  
  26. else
  27. {
  28. try {// שלב א: טעינת המתפעל - דרייבר
  29. Class.forName("com.mysql.jdbc.Driver").newInstance();
  30.  
  31. //שלב ב:חיבור למסד הנתונים
  32. Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/members", "root", "MyNewPass");
  33.  
  34. //שלב ג: יצירת עצם הסטיטמנט "שידבר" עם מסד הנתונים,
  35. Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
  36.  
  37. // Statement st = con.createStatement(); // כאשר אין פרמטרים, אז אי אפשר לנוע למעלה - למטה בתוך הרזלטסט
  38.  
  39. String s = request.getParameter("username");
  40.  
  41. String mySQL = "SELECT * FROM allusers WHERE username='" + s + "'";
  42.  
  43. //שלב ה: יצירת הרזלטסט - טבלה המחזיקה בתוכה חלק מ-(לפעמים את כל) מסד הנתונים
  44. ResultSet oRS = st.executeQuery(mySQL);
  45.  
  46. //=====================סוף ההתחברות למסד הנתונים======================
  47.  
  48. if (oRS.next())
  49. {
  50. session.setAttribute("EnterSite","ok");
  51. response.sendRedirect("homepage.jsp");
  52. %>
  53. <script type = text/javascript>
  54. window.alert("נכנסת בהצלחה");
  55. </script>
  56. <%
  57. }
  58. else
  59. {
  60. session.setAttribute("EnterSite","notok");
  61. response.sendRedirect("homepage.jsp");
  62. %>
  63. <script type = text/javascript>
  64. window.alert("אתה לא משתמש רשום");
  65. </script>
  66. <%
  67. }
  68. }
  69. catch (Exception e) {
  70. System.out.println(e.getMessage());
  71. System.out.println("Error in connecting");
  72. out.println("Error in connecting");
  73. } // the connection is closed
  74. }
  75.  
  76. finally
  77. {
  78. session.setAttribute ("EnterSite","notok");
  79. }
  80. %>
  81.  
  82.  
  83. </body>
  84. </html>
Add Comment
Please, Sign In to add comment