Advertisement
Parasect

htmlexam2

Feb 21st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. <%--
  2. Document : index
  3. Created on : 05/08/2010, 21:19:49
  4. Author : IP
  5. --%>
  6.  
  7. <%@page import="MyClasses.MyUtils"%>
  8. <%@page import="java.sql.ResultSet"%>
  9. <%@page import="java.sql.Statement"%>
  10. <%@page import="java.sql.Connection"%>
  11. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  12.  
  13. <html>
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  16. <title>JSP Page</title>
  17. <script type="text/javascript">
  18. function checkForm()
  19. {
  20. var email = document.orderForm.email.value;
  21. var productName = document.orderForm.productName.value;
  22. var quantity = document.orderForm.quantity.value;
  23. if(!checkEmail(email))
  24. {
  25. window.alert("Email invalid");
  26. document.orderForm.email.focus();
  27. document.orderForm.email.select();
  28. return false;
  29. }
  30. if(!checkProductName(productName))
  31. {
  32. window.alert("productname invalid");
  33. document.orderForm.productName.focus();
  34. document.orderForm.productName.select();
  35. return false;
  36. }
  37. if(!checkQuantity(quantity))
  38. {
  39. window.alert("quantity invalid");
  40. document.orderForm.quantity.focus();
  41. document.orderForm.quantity.select();
  42. return false;
  43. }
  44. }
  45. function checkEmail(email)
  46. {
  47. if(email.length < 8)
  48. {
  49. return false;
  50. }
  51. var i;
  52. var isSifra = false;
  53. var isAfterShtrudel = false;
  54. var isDotAfterShtrudel = false;
  55. for (i = 0; i < email.length; i++) {
  56. if(email[i] >= '0' && email[i] <= '9')
  57. {
  58. isSifra = true;
  59. }
  60. else if(email[i] === '@'){
  61. isAfterShtrudel = true;
  62. }
  63. else if(email[i] === '.' && isAfterShtrudel){
  64. isDotAfterShtrudel = true;
  65. }
  66. else if(!(email[i] >= '!' && email[i] <= '~'))
  67. return false; //אותיות באנגלית וסימנים
  68. //כפי שנאמר
  69. }
  70. if(isSifra === false)
  71. return false;
  72. return isDotAfterShtrudel;
  73.  
  74. }
  75. function checkProductName(productName)
  76. {
  77. if(productName.length < 10)
  78. {
  79. return false;
  80. }
  81. var pattern = /^[A-Z][^0-9^@^?^\/^#]*[a-z]$/;
  82. return pattern.test(productName);
  83. }
  84. function checkQuantity(quantity)
  85. {
  86. var quantityInt = parseInt(quantity);
  87. return (quantityInt > 0);
  88. }
  89. </script>
  90. </head>
  91. <body dir="rtl">
  92. <br><br>
  93. <center>
  94. <h2><b><u>טופס הזמנת מוצר מחברה</u></b></h2><br><br>
  95. </center>
  96. <form name="orderForm" method="get" onsubmit = "return checkForm()" action = "insertToDB.jsp">
  97.  
  98. <div>
  99. <table dir="rtl" align="center" border="0">
  100.  
  101. <tr>
  102. <td><font size="3" color="blue">מספר הזמנה:</font></td>
  103. <td><input type="text" name="orderNum" maxlength="6"></td>
  104. </tr>
  105.  
  106. <tr>
  107. <td><font size="3" color="blue">email:</font></td>
  108. <td><input type="text" name="email"></td>
  109. </tr>
  110. <tr>
  111.  
  112. <td><font size="3" color="blue">שם מוצר:</font></td>
  113. <td><input type="text" name="productName"></td>
  114. </tr>
  115.  
  116. <tr>
  117. <td><font size="3" color="blue">מחיר מוצר:</font></td>
  118. <td><input type="text" name="productPrice"></td>
  119. </tr>
  120.  
  121. <tr>
  122. <td><font size="3" color="blue">כמות:</font></td>
  123. <td><input type="text" name="quantity"></td>
  124. </tr>
  125.  
  126. <tr >
  127. <td> <br><br><br></td>
  128. </tr>
  129.  
  130. <tr>
  131. <td><input type="submit" value="שלח" /></td>
  132. <td><input type="reset" value="נקה"/></td>
  133. </tr>
  134.  
  135. </table>
  136.  
  137. </form>
  138.  
  139. </body>
  140. </html>
  141.  
  142.  
  143.  
  144. <%--
  145. Document : insertToDB
  146. Created on : 16/08/2010, 00:06:59
  147. Author : IP
  148. --%>
  149.  
  150. <%@page import="MyClasses.MyUtils"%>
  151. <%@page import="java.sql.ResultSet"%>
  152. <%@page import="java.sql.Statement"%>
  153. <%@page import="java.sql.Connection"%>
  154.  
  155. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  156.  
  157. <%
  158. request.setCharacterEncoding("UTF-8"); //o קידוד לעברית
  159.  
  160. // קבלת ערכי השדות מצד לקוח לצד שרת
  161. String orderNum = request.getParameter("orderNum");
  162. String email = request.getParameter("email");
  163. String productName = request.getParameter("productName");
  164. String productPrice = request.getParameter("productPrice");
  165. String quantity = request.getParameter("quantity");
  166.  
  167.  
  168. //O שלב שני - קישור למסד הנתונים
  169. Connection con = MyUtils.getSiteDBconnection(application, "db\\siteDB.mdb");
  170. Statement stmt = con.createStatement();
  171.  
  172. if(orderNum==null)
  173. orderNum= "1";
  174.  
  175. //o יצירת שאילתת בחירה למסד לצורך בדיקת קיום המשתמש
  176. String sql = "SELECT * FROM orders WHERE orderNum='" + orderNum + "'";
  177. ResultSet rs = stmt.executeQuery(sql);
  178.  
  179. //o בדיקה האם קיים משתמש
  180. if(rs.next())
  181. {
  182. out.println("<center><h3>Ordernum already registred.</h3></center><br>");
  183. }
  184. else
  185. {
  186. sql = "INSERT INTO orders (orderNum, email, productName, productPrice, quantity)"
  187. + " VALUES" + "('" + orderNum + "','"+ email +"','"+ productName + "','"+ productPrice +"','"+ quantity + "');";
  188.  
  189. stmt.executeUpdate(sql);
  190.  
  191. // stmt.execute(sql);
  192.  
  193. out.print("<center><h3>"+"הזמנה מספר: " + orderNum + " של מוצר: " + productName
  194. + " <br/>נוספה בהצלחה. "+"</h3></center><br>");
  195. out.print("<br>"+"<a href='index.jsp'>חזרה לרישום</a>");
  196.  
  197. }
  198.  
  199. //O סגירת הקשר עם מסד הנתונים
  200.  
  201. stmt.close();
  202. con.close();
  203. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement