D:\Sam\InterviewsMaterial\SiteWorx\SiteWorxTest\web\jsp\serverSideCalculation.jsp
  1 <%-- 
  2     Document   : serverSideCalculation
  3     Created on : Oct 8, 2013, 2:38:02 PM
  4     Author     : sameldin
  5 --%>
  6 <%@ page import="java.util.ArrayList"%>
  7 <%@ page import="java.io.*"%>
  8 <%@ page import="constants.*"%>
  9 <%@ page import="utils.*"%>
 10 
 11 <%@page contentType="text/html" pageEncoding="UTF-8"%>
 12 <!DOCTYPE html>
 13 <script language="JavaScript" type="text/javascript">
 14         //========================================
 15         function sortNumber(num1, num2) 
 16         {
 17             return num1 - num2;
 18         }
 19         //================================
 20         function checkInput4Errors()
 21         {
 22             var localStringOfDigits =  document.getElementById('inputTextArea').value;
 23             var stringOfDigits = localStringOfDigits.split(',');
 24             var sortedArrayOfDigits = stringOfDigits.sort(sortNumber);
 25             var arrayLength = localStringOfDigits.split(",").length;
 26             var count = 0;
 27             var outputStringOfDigits = "";
 28             for(count = 0; count < arrayLength; count++)
 29             {
 30                 var elementValue = sortedArrayOfDigits[count];
 31                 if(elementValue == "")
 32                     continue;
 33                 if(isNaN(elementValue))
 34                 {
 35                     alert('===> This value is not a digit and will NOT be added to the list = ' + elementValue);
 36                 }
 37                 else if (count < (arrayLength - 1))
 38                 {                   
 39                    outputStringOfDigits += elementValue + ",";
 40                 } 
 41                 else
 42                     {
 43                        outputStringOfDigits += elementValue;                        
 44                     }
 45             }
 46             document.getElementById('inputTextArea').value = outputStringOfDigits;
 47         }
 48         //================================
 49         function submitDigits()
 50         {
 51             // alert("Due to Hosting issue, our Forms are not working at this point and please accept our apologies.");
 52                 // return;
 53                 checkInput4Errors();
 54                 if(document.getElementById('inputTextArea').value == "")
 55                 {
 56                     alert('===> This input has no digits and will NOT uploaded to the server');    
 57                     return;
 58                 }
 59                 var parameterString = "<%=Constants.USER_ID_NUMBER_STRING%>="
 60                                 + document.getElementById('<%=Constants.USER_ID_NUMBER_STRING%>').value
 61                                 + "&"
 62                                 + "<%=Constants.USER_FIRST_NAME_STRING%>="
 63                                 + document.getElementById('<%=Constants.USER_FIRST_NAME_STRING%>').value
 64                                 + "&"
 65                                 + "<%=Constants.USER_LAST_NAME_STRING%>="
 66                                 + document.getElementById('<%=Constants.USER_LAST_NAME_STRING%>').value                            
 67                                 + "&"
 68                                 + "<%=Constants.USER_EMAIL_ADDRESS_STRING%>="
 69                                 + document.getElementById('<%=Constants.USER_EMAIL_ADDRESS_STRING%>').value
 70                                 + "&"
 71                                 + "<%=Constants.STRING_OF_DIGITS%>="
 72                                 + document.getElementById('inputTextArea').value;
 73 
 74 alert("==> " + parameterString);
 75                document.stringOfDigitNumbersForm.action="/SiteWorxTest/SiteWorxFormServlet_P2?" + parameterString;
 76                document.stringOfDigitNumbersForm.submit();
 77         }
 78 //==========================================
 79 </script>
 80 <html>
 81     <head>
 82         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 83         <title>JSP Page</title>
 84     </head>
 85  <body>
 86 <FORM name="stringOfDigitNumbersForm" id="stringOfDigitNumbersForm"  action="" method="post" enctype="text/plain">
 87 <input type="hidden" name="<%=Constants.STRING_OF_DIGITS%>"                   value="">
 88 <!--   ************************** -->
 89 <TABLE  bgcolor="black"     WIDTH="50%" ALIGN=LEFT      BORDER=0        style="clear: left;">
 90         </TR>
 91             <TH>
 92                 <img    
 93                         border="0"      
 94                         src="../images/TechnicalAssessment2.bmp" 
 95                         width="120" 
 96                         height="10"
 97                         ALT="Technical Assessment"
 98                         ALIGN="LEFT"
 99                 >
100                 </TH>
101         </TR>
102 </TABLE>
103 <!--   ************************** -->
104 <BR>
105 <h2>Technical Assessment Test (Series of 5 Digit Numbers) - Part 2</h2>
106 <h3>This JSP is designed for the following:</h3> 
107 <TABLE WIDTH="50%" BORDER=0 >
108                         <TR>
109                                 <TH     ALIGN=RIGHT VALIGN=TOP  WIDTH=20 style="font-size: 10pt; font-weight: normal; color: black">
110                 <Font size=4    face=helvetica>
111                 •
112                 </font>
113                                 </TH>
114                                 <TH     ALIGN=LEFT VALIGN=TOP   style="font-size: 10pt; font-weight: normal; color: black">
115 Take up any number of  digits entries between 1 and 99,999
116                                 </TH>
117                         </TR>
118                         <TR>
119                                 <TH     ALIGN=RIGHT VALIGN=TOP  WIDTH=20 style="font-size: 10pt; font-weight: normal; color: black">
120                 <Font size=4    face=helvetica>
121                 •
122                 </font>
123                                 </TH>
124                                 <TH     ALIGN=LEFT VALIGN=TOP   style="font-size: 10pt; font-weight: normal; color: black">
125 Calculate: Sum, Average, Median, Highest and Lowest Numbers of the User's Input
126                                 </TH>
127                         </TR>
128                         <TR>
129                                 <TH     ALIGN=RIGHT VALIGN=TOP  WIDTH=20 style="font-size: 10pt; font-weight: normal; color: black">
130                 <Font size=4    face=helvetica>
131                 •
132                 </font>
133                                 </TH>
134                                 <TH     ALIGN=LEFT VALIGN=TOP   style="font-size: 10pt; font-weight: normal; color: black">
135 It also demo doing the calculation on the sever side and not the browser side.
136                                 </TH>
137                         </TR>
138                         <TR>
139                                 <TH     ALIGN=RIGHT VALIGN=TOP  WIDTH=20 style="font-size: 10pt; font-weight: normal; color: black">
140                 <Font size=4    face=helvetica>
141                 •
142                 </font>
143                                 </TH>
144                                 <TH     ALIGN=LEFT VALIGN=TOP   style="font-size: 10pt; font-weight: normal; color: black">
145 The values are uploaded to server for server side tasks (Submit).
146                                 </TH>
147                         </TR>
148 </TABLE>
149 <!--   ************************** -->
150 <TABLE  WIDTH="600"  BORDER="0" CELLPADDING="0">
151         <TR>
152                                         <TH     WIDTH="100"     ALIGN=LEFT      VALIGN=TOP      sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
153 First Name:
154                                         </TH>
155                                         <TH     ALIGN=LEFT      WIDTH="200"     sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
156                                                 <input type="input" id="<%=Constants.USER_FIRST_NAME_STRING%>" name="<%=Constants.USER_FIRST_NAME_STRING%>" value="Sam" style="font-size: 8pt; font-weight: normal; color: #000000;"    width:180;height:15"    disabled="disabled">
157                                         </TH>
158                                         <TH     WIDTH="100"     ALIGN=LEFT      VALIGN=TOP      sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
159 Last Name:
160                                         </TH>
161                                         <TH     ALIGN=LEFT      WIDTH="200"     sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
162                                                 <input type="input" id="<%=Constants.USER_LAST_NAME_STRING%>" name="<%=Constants.USER_LAST_NAME_STRING%>" value="Eldin" style="font-size: 8pt; font-weight: normal; color: #000000;"    width:180;height:15"    disabled="disabled">
163                                         </TH>
164         </TR>
165         <TR>
166                                         <TH     WIDTH="100"     ALIGN=LEFT      VALIGN=TOP      sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
167 User ID:
168                                         </TH>
169                                         <TH     ALIGN=LEFT      WIDTH="200"     sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
170                                                 <input type="input" id="<%=Constants.USER_ID_NUMBER_STRING%>" name="<%=Constants.USER_ID_NUMBER_STRING%>" value="123"   style="font-size: 8pt; font-weight: normal; color: #000000;"    width:180;height:15"    disabled="disabled">
171                                         </TH>
172                                         <TH     WIDTH="100"     ALIGN=LEFT      VALIGN=TOP      sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
173 Email:
174                                         </TH>
175                                         <TH     ALIGN=LEFT      WIDTH="200"     sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
176                                                 <input type="input" id="<%=Constants.USER_EMAIL_ADDRESS_STRING%>" name="<%=Constants.USER_EMAIL_ADDRESS_STRING%>" value="Sam@SamEldin.com"      style="font-size: 8pt; font-weight: normal; color: #000000;"    width:180;height:15"    disabled="disabled">
177                                         </TH>
178         </TR>
179 </TABLE>
180 
181 <BR>
182 
183 <!--   ************************** -->
184 <TABLE WIDTH="50%"      bgcolor="white"  ALIGN=LEFT     BORDER=0        style="clear: left;">
185                 <TR>
186                                 <TH BGCOLOR="#006699" ALIGN=Center VALIGN=TOP sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
187 <font  color=white  size=3 face="TimesRoman">
188 User Input
189 </font>
190                                 </TH>
191                 </TR>
192                 <TR>
193                                 <TH BGCOLOR="#006699" ALIGN=Center VALIGN=TOP sans-serif; style="font-size: 10pt; font-weight: normal; color: #000000">
194                                 </TH>
195                 </TR>
196 </TABLE>
197 <BR>
198 <BR>
199 <h3>Enter user input number separated by comma, for example: 123,543,654,99999</h3> 
200 <BR>
201 <BR>
202 <textarea  id="inputTextArea"   name="inputTextArea"    rows="5"   maxlength='500'  STYLE="width:40%">
203 
204 </textarea>
205 <BR>
206 <BR>
207 <TABLE  bgcolor="white"  ALIGN=LEFT     BORDER=0        style="clear: left;">
208         </TR>
209                 <TH     WIDTH="230"     ALIGN=LEFT      VALIGN=TOP      sans-serif; style="font-size: 14pt; font-weight: normal; color: #000000">
210                         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
211                 </TH>
212                 <TH     ALIGN=LEFT      sans-serif; style="font-size: 12pt; font-weight: normal; color: #000000">
213                         <button style="font-size: 12pt; font-weight: normal; color: #006699;    width:120;"     onClick="reset();">Reset</button>
214                         <button style="font-size: 12pt; font-weight: normal; color: #006699;    width:120;"     onClick="submitDigits();">Submit</button>
215                 </TH>
216         <TR>
217 </TABLE>
218 </body>
219 </html>
220