Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%--
- Document : index
- Created on : 05/08/2010, 21:19:49
- Author : IP
- --%>
- <%@page import="MyClasses.MyUtils"%>
- <%@page import="java.sql.ResultSet"%>
- <%@page import="java.sql.Statement"%>
- <%@page import="java.sql.Connection"%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- <script type="text/javascript">
- function checkForm()
- {
- var email = document.orderForm.email.value;
- var productName = document.orderForm.productName.value;
- var quantity = document.orderForm.quantity.value;
- if(!checkEmail(email))
- {
- window.alert("Email invalid");
- document.orderForm.email.focus();
- document.orderForm.email.select();
- return false;
- }
- if(!checkProductName(productName))
- {
- window.alert("productname invalid");
- document.orderForm.productName.focus();
- document.orderForm.productName.select();
- return false;
- }
- if(!checkQuantity(quantity))
- {
- window.alert("quantity invalid");
- document.orderForm.quantity.focus();
- document.orderForm.quantity.select();
- return false;
- }
- }
- function checkEmail(email)
- {
- if(email.length < 8)
- {
- return false;
- }
- var i;
- var isSifra = false;
- var isAfterShtrudel = false;
- var isDotAfterShtrudel = false;
- for (i = 0; i < email.length; i++) {
- if(email[i] >= '0' && email[i] <= '9')
- {
- isSifra = true;
- }
- else if(email[i] === '@'){
- isAfterShtrudel = true;
- }
- else if(email[i] === '.' && isAfterShtrudel){
- isDotAfterShtrudel = true;
- }
- else if(!(email[i] >= '!' && email[i] <= '~'))
- return false; //אותיות באנגלית וסימנים
- //כפי שנאמר
- }
- if(isSifra === false)
- return false;
- return isDotAfterShtrudel;
- }
- function checkProductName(productName)
- {
- if(productName.length < 10)
- {
- return false;
- }
- var pattern = /^[A-Z][^0-9^@^?^\/^#]*[a-z]$/;
- return pattern.test(productName);
- }
- function checkQuantity(quantity)
- {
- var quantityInt = parseInt(quantity);
- return (quantityInt > 0);
- }
- </script>
- </head>
- <body dir="rtl">
- <br><br>
- <center>
- <h2><b><u>טופס הזמנת מוצר מחברה</u></b></h2><br><br>
- </center>
- <form name="orderForm" method="get" onsubmit = "return checkForm()" action = "insertToDB.jsp">
- <div>
- <table dir="rtl" align="center" border="0">
- <tr>
- <td><font size="3" color="blue">מספר הזמנה:</font></td>
- <td><input type="text" name="orderNum" maxlength="6"></td>
- </tr>
- <tr>
- <td><font size="3" color="blue">email:</font></td>
- <td><input type="text" name="email"></td>
- </tr>
- <tr>
- <td><font size="3" color="blue">שם מוצר:</font></td>
- <td><input type="text" name="productName"></td>
- </tr>
- <tr>
- <td><font size="3" color="blue">מחיר מוצר:</font></td>
- <td><input type="text" name="productPrice"></td>
- </tr>
- <tr>
- <td><font size="3" color="blue">כמות:</font></td>
- <td><input type="text" name="quantity"></td>
- </tr>
- <tr >
- <td> <br><br><br></td>
- </tr>
- <tr>
- <td><input type="submit" value="שלח" /></td>
- <td><input type="reset" value="נקה"/></td>
- </tr>
- </table>
- </form>
- </body>
- </html>
- <%--
- Document : insertToDB
- Created on : 16/08/2010, 00:06:59
- Author : IP
- --%>
- <%@page import="MyClasses.MyUtils"%>
- <%@page import="java.sql.ResultSet"%>
- <%@page import="java.sql.Statement"%>
- <%@page import="java.sql.Connection"%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%
- request.setCharacterEncoding("UTF-8"); //o קידוד לעברית
- // קבלת ערכי השדות מצד לקוח לצד שרת
- String orderNum = request.getParameter("orderNum");
- String email = request.getParameter("email");
- String productName = request.getParameter("productName");
- String productPrice = request.getParameter("productPrice");
- String quantity = request.getParameter("quantity");
- //O שלב שני - קישור למסד הנתונים
- Connection con = MyUtils.getSiteDBconnection(application, "db\\siteDB.mdb");
- Statement stmt = con.createStatement();
- if(orderNum==null)
- orderNum= "1";
- //o יצירת שאילתת בחירה למסד לצורך בדיקת קיום המשתמש
- String sql = "SELECT * FROM orders WHERE orderNum='" + orderNum + "'";
- ResultSet rs = stmt.executeQuery(sql);
- //o בדיקה האם קיים משתמש
- if(rs.next())
- {
- out.println("<center><h3>Ordernum already registred.</h3></center><br>");
- }
- else
- {
- sql = "INSERT INTO orders (orderNum, email, productName, productPrice, quantity)"
- + " VALUES" + "('" + orderNum + "','"+ email +"','"+ productName + "','"+ productPrice +"','"+ quantity + "');";
- stmt.executeUpdate(sql);
- // stmt.execute(sql);
- out.print("<center><h3>"+"הזמנה מספר: " + orderNum + " של מוצר: " + productName
- + " <br/>נוספה בהצלחה. "+"</h3></center><br>");
- out.print("<br>"+"<a href='index.jsp'>חזרה לרישום</a>");
- }
- //O סגירת הקשר עם מסד הנתונים
- stmt.close();
- con.close();
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement