JSP Addressbook app for VIP Express (circa Jun 2002)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

269 lines
9.6 KiB

  1. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ include file="Connections/jimi.jsp" %>
  3. <%
  4. Driver DriverAddressList = (Driver)Class.forName(MM_jimi_DRIVER).newInstance();
  5. Connection ConnAddressList = DriverManager.getConnection(MM_jimi_STRING,MM_jimi_USERNAME,MM_jimi_PASSWORD);
  6. PreparedStatement StatementAddressList = ConnAddressList.prepareStatement("SELECT nick,name,street,city,state,zipcode FROM address");
  7. ResultSet AddressList = StatementAddressList.executeQuery();
  8. boolean AddressList_isEmpty = !AddressList.next();
  9. boolean AddressList_hasData = !AddressList_isEmpty;
  10. Object AddressList_data;
  11. int AddressList_numRows = 0;
  12. %>
  13. <%
  14. int Repeat1__numRows = 35;
  15. int Repeat1__index = 0;
  16. AddressList_numRows += Repeat1__numRows;
  17. %>
  18. <%
  19. // *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
  20. int AddressList_first = 1;
  21. int AddressList_last = 1;
  22. int AddressList_total = -1;
  23. if (AddressList_isEmpty) {
  24. AddressList_total = AddressList_first = AddressList_last = 0;
  25. }
  26. //set the number of rows displayed on this page
  27. if (AddressList_numRows == 0) {
  28. AddressList_numRows = 1;
  29. }
  30. %>
  31. <%
  32. // *** Recordset Stats: if we don't know the record count, manually count them
  33. if (AddressList_total == -1) {
  34. // count the total records by iterating through the recordset
  35. for (AddressList_total = 1; AddressList.next(); AddressList_total++);
  36. // reset the cursor to the beginning
  37. AddressList.close();
  38. AddressList = StatementAddressList.executeQuery();
  39. AddressList_hasData = AddressList.next();
  40. // set the number of rows displayed on this page
  41. if (AddressList_numRows < 0 || AddressList_numRows > AddressList_total) {
  42. AddressList_numRows = AddressList_total;
  43. }
  44. // set the first and last displayed record
  45. AddressList_first = Math.min(AddressList_first, AddressList_total);
  46. AddressList_last = Math.min(AddressList_first + AddressList_numRows - 1, AddressList_total);
  47. }
  48. %>
  49. <% String MM_paramName = ""; %>
  50. <%
  51. // *** Move To Record and Go To Record: declare variables
  52. ResultSet MM_rs = AddressList;
  53. int MM_rsCount = AddressList_total;
  54. int MM_size = AddressList_numRows;
  55. String MM_uniqueCol = "";
  56. MM_paramName = "";
  57. int MM_offset = 0;
  58. boolean MM_atTotal = false;
  59. boolean MM_paramIsDefined = (MM_paramName.length() != 0 && request.getParameter(MM_paramName) != null);
  60. %>
  61. <%
  62. // *** Move To Record: handle 'index' or 'offset' parameter
  63. if (!MM_paramIsDefined && MM_rsCount != 0) {
  64. //use index parameter if defined, otherwise use offset parameter
  65. String r = request.getParameter("index");
  66. if (r==null) r = request.getParameter("offset");
  67. if (r!=null) MM_offset = Integer.parseInt(r);
  68. // if we have a record count, check if we are past the end of the recordset
  69. if (MM_rsCount != -1) {
  70. if (MM_offset >= MM_rsCount || MM_offset == -1) { // past end or move last
  71. if (MM_rsCount % MM_size != 0) // last page not a full repeat region
  72. MM_offset = MM_rsCount - MM_rsCount % MM_size;
  73. else
  74. MM_offset = MM_rsCount - MM_size;
  75. }
  76. }
  77. //move the cursor to the selected record
  78. int i;
  79. for (i=0; AddressList_hasData && (i < MM_offset || MM_offset == -1); i++) {
  80. AddressList_hasData = MM_rs.next();
  81. }
  82. if (!AddressList_hasData) MM_offset = i; // set MM_offset to the last possible record
  83. }
  84. %>
  85. <%
  86. // *** Move To Record: if we dont know the record count, check the display range
  87. if (MM_rsCount == -1) {
  88. // walk to the end of the display range for this page
  89. int i;
  90. for (i=MM_offset; AddressList_hasData && (MM_size < 0 || i < MM_offset + MM_size); i++) {
  91. AddressList_hasData = MM_rs.next();
  92. }
  93. // if we walked off the end of the recordset, set MM_rsCount and MM_size
  94. if (!AddressList_hasData) {
  95. MM_rsCount = i;
  96. if (MM_size < 0 || MM_size > MM_rsCount) MM_size = MM_rsCount;
  97. }
  98. // if we walked off the end, set the offset based on page size
  99. if (!AddressList_hasData && !MM_paramIsDefined) {
  100. if (MM_offset > MM_rsCount - MM_size || MM_offset == -1) { //check if past end or last
  101. if (MM_rsCount % MM_size != 0) //last page has less records than MM_size
  102. MM_offset = MM_rsCount - MM_rsCount % MM_size;
  103. else
  104. MM_offset = MM_rsCount - MM_size;
  105. }
  106. }
  107. // reset the cursor to the beginning
  108. AddressList.close();
  109. AddressList = StatementAddressList.executeQuery();
  110. AddressList_hasData = AddressList.next();
  111. MM_rs = AddressList;
  112. // move the cursor to the selected record
  113. for (i=0; AddressList_hasData && i < MM_offset; i++) {
  114. AddressList_hasData = MM_rs.next();
  115. }
  116. }
  117. %>
  118. <%
  119. // *** Move To Record: update recordset stats
  120. // set the first and last displayed record
  121. AddressList_first = MM_offset + 1;
  122. AddressList_last = MM_offset + MM_size;
  123. if (MM_rsCount != -1) {
  124. AddressList_first = Math.min(AddressList_first, MM_rsCount);
  125. AddressList_last = Math.min(AddressList_last, MM_rsCount);
  126. }
  127. // set the boolean used by hide region to check if we are on the last record
  128. MM_atTotal = (MM_rsCount != -1 && MM_offset + MM_size >= MM_rsCount);
  129. %>
  130. <%
  131. // *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
  132. String MM_keepBoth,MM_keepURL="",MM_keepForm="",MM_keepNone="";
  133. String[] MM_removeList = { "index", MM_paramName };
  134. // create the MM_keepURL string
  135. if (request.getQueryString() != null) {
  136. MM_keepURL = '&' + request.getQueryString();
  137. for (int i=0; i < MM_removeList.length && MM_removeList[i].length() != 0; i++) {
  138. int start = MM_keepURL.indexOf(MM_removeList[i]) - 1;
  139. if (start >= 0 && MM_keepURL.charAt(start) == '&' &&
  140. MM_keepURL.charAt(start + MM_removeList[i].length() + 1) == '=') {
  141. int stop = MM_keepURL.indexOf('&', start + 1);
  142. if (stop == -1) stop = MM_keepURL.length();
  143. MM_keepURL = MM_keepURL.substring(0,start) + MM_keepURL.substring(stop);
  144. }
  145. }
  146. }
  147. // add the Form variables to the MM_keepForm string
  148. if (request.getParameterNames().hasMoreElements()) {
  149. java.util.Enumeration items = request.getParameterNames();
  150. while (items.hasMoreElements()) {
  151. String nextItem = (String)items.nextElement();
  152. boolean found = false;
  153. for (int i=0; !found && i < MM_removeList.length; i++) {
  154. if (MM_removeList[i].equals(nextItem)) found = true;
  155. }
  156. if (!found && MM_keepURL.indexOf('&' + nextItem + '=') == -1) {
  157. MM_keepForm = MM_keepForm + '&' + nextItem + '=' + java.net.URLEncoder.encode(request.getParameter(nextItem));
  158. }
  159. }
  160. }
  161. // create the Form + URL string and remove the intial '&' from each of the strings
  162. MM_keepBoth = MM_keepURL + MM_keepForm;
  163. if (MM_keepBoth.length() > 0) MM_keepBoth = MM_keepBoth.substring(1);
  164. if (MM_keepURL.length() > 0) MM_keepURL = MM_keepURL.substring(1);
  165. if (MM_keepForm.length() > 0) MM_keepForm = MM_keepForm.substring(1);
  166. %>
  167. <%
  168. // *** Move To Record: set the strings for the first, last, next, and previous links
  169. String MM_moveFirst,MM_moveLast,MM_moveNext,MM_movePrev;
  170. {
  171. String MM_keepMove = MM_keepBoth; // keep both Form and URL parameters for moves
  172. String MM_moveParam = "index=";
  173. // if the page has a repeated region, remove 'offset' from the maintained parameters
  174. if (MM_size > 1) {
  175. MM_moveParam = "offset=";
  176. int start = MM_keepMove.indexOf(MM_moveParam);
  177. if (start != -1 && (start == 0 || MM_keepMove.charAt(start-1) == '&')) {
  178. int stop = MM_keepMove.indexOf('&', start);
  179. if (start == 0 && stop != -1) stop++;
  180. if (stop == -1) stop = MM_keepMove.length();
  181. if (start > 0) start--;
  182. MM_keepMove = MM_keepMove.substring(0,start) + MM_keepMove.substring(stop);
  183. }
  184. }
  185. // set the strings for the move to links
  186. StringBuffer urlStr = new StringBuffer(request.getRequestURI()).append('?').append(MM_keepMove);
  187. if (MM_keepMove.length() > 0) urlStr.append('&');
  188. urlStr.append(MM_moveParam);
  189. MM_moveFirst = urlStr + "0";
  190. MM_moveLast = urlStr + "-1";
  191. MM_moveNext = urlStr + Integer.toString(MM_offset+MM_size);
  192. MM_movePrev = urlStr + Integer.toString(Math.max(MM_offset-MM_size,0));
  193. }
  194. %>
  195. <html>
  196. <head>
  197. <title>Test Document</title>
  198. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  199. <link href="style/common.css" rel="stylesheet" type="text/css">
  200. </head>
  201. <body>
  202. <table cellpadding="0" cellspacing="2" class="data">
  203. <tr>
  204. <th>name</th><th>street</th><th>city</th><th>state</th><th>zipcode</th>
  205. </tr>
  206. <% int row = 0; while ((AddressList_hasData)&&(Repeat1__numRows-- != 0)) { %>
  207. <tr class="<%=(row++ % 2 == 1) ? "dark" : "light"%>">
  208. <td><%=(((AddressList_data = AddressList.getObject("name"))==null || AddressList.wasNull())?"":AddressList_data)%></td>
  209. <td><%=(((AddressList_data = AddressList.getObject("street"))==null || AddressList.wasNull())?"":AddressList_data)%></td>
  210. <td><%=(((AddressList_data = AddressList.getObject("city"))==null || AddressList.wasNull())?"":AddressList_data)%></td>
  211. <td><%=(((AddressList_data = AddressList.getObject("state"))==null || AddressList.wasNull())?"":AddressList_data)%></td>
  212. <td><%=(((AddressList_data = AddressList.getObject("zipcode"))==null || AddressList.wasNull())?"":AddressList_data)%></td>
  213. </tr>
  214. <%
  215. Repeat1__index++;
  216. AddressList_hasData = AddressList.next();
  217. }
  218. %>
  219. <tr valign="bottom" class="status">
  220. <td colspan=5>
  221. <span class="left">
  222. <%=(AddressList_first)%> to <%=(AddressList_last)%> of <%=(AddressList_total)%>
  223. </span>
  224. <span class="right">
  225. <% if (MM_offset !=0) { %>
  226. <a href="<%=MM_movePrev%>"><img src="Previous.gif" border=0></a>
  227. <% } /* end MM_offset != 0 */ %>
  228. <% if (!MM_atTotal) { %>
  229. <a href="<%=MM_moveNext%>"><img src="Next.gif" border=0></a>
  230. <% } /* end !MM_atTotal */ %>
  231. </span>
  232. </td>
  233. </tr>
  234. </table>
  235. </body>
  236. </html>
  237. <%
  238. AddressList.close();
  239. StatementAddressList.close();
  240. ConnAddressList.close();
  241. %>