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.

139 lines
5.3 KiB

  1. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ include file="Connections/jimi.jsp" %>
  3. <%
  4. // *** Edit Operations: declare variables
  5. // set the form action variable
  6. String MM_editAction = request.getRequestURI();
  7. if (request.getQueryString() != null && request.getQueryString().length() > 0) {
  8. MM_editAction += "?" + request.getQueryString();
  9. }
  10. // connection information
  11. String MM_editDriver = null, MM_editConnection = null, MM_editUserName = null, MM_editPassword = null;
  12. // redirect information
  13. String MM_editRedirectUrl = null;
  14. // query string to execute
  15. StringBuffer MM_editQuery = null;
  16. // boolean to abort record edit
  17. boolean MM_abortEdit = false;
  18. // table information
  19. String MM_editTable = null, MM_editColumn = null, MM_recordId = null;
  20. // form field information
  21. String[] MM_fields = null, MM_columns = null;
  22. %>
  23. <%
  24. // *** Insert Record: set variables
  25. if (request.getParameter("MM_insert") != null && request.getParameter("MM_insert").toString().equals("form1")) {
  26. MM_editDriver = MM_jimi_DRIVER;
  27. MM_editConnection = MM_jimi_STRING;
  28. MM_editUserName = MM_jimi_USERNAME;
  29. MM_editPassword = MM_jimi_PASSWORD;
  30. MM_editTable = "address";
  31. MM_editRedirectUrl = "";
  32. String MM_fieldsStr = "id|value|nick|value|name|value|street|value|city|value|state|value|zipcode|value|zipext|value|phone|value|areacode|value";
  33. String MM_columnsStr = "id|none,none,NULL|nick|',none,''|name|',none,''|street|',none,''|city|',none,''|state|none,none,NULL|zipcode|none,none,NULL|zipext|none,none,NULL|phone|',none,''|areacode|',none,''";
  34. // create the MM_fields and MM_columns arrays
  35. java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_fieldsStr,"|");
  36. MM_fields = new String[tokens.countTokens()];
  37. for (int i=0; tokens.hasMoreTokens(); i++) MM_fields[i] = tokens.nextToken();
  38. tokens = new java.util.StringTokenizer(MM_columnsStr,"|");
  39. MM_columns = new String[tokens.countTokens()];
  40. for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] = tokens.nextToken();
  41. // set the form values
  42. for (int i=0; i+1 < MM_fields.length; i+=2) {
  43. MM_fields[i+1] = ((request.getParameter(MM_fields[i])!=null)?(String)request.getParameter(MM_fields[i]):"");
  44. }
  45. // append the query string to the redirect URL
  46. if (MM_editRedirectUrl.length() != 0 && request.getQueryString() != null) {
  47. MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + request.getQueryString();
  48. }
  49. }
  50. %>
  51. <%
  52. // *** Insert Record: construct a sql insert statement and execute it
  53. if (request.getParameter("MM_insert") != null) {
  54. // create the insert sql statement
  55. StringBuffer MM_tableValues = new StringBuffer(), MM_dbValues = new StringBuffer();
  56. for (int i=0; i+1 < MM_fields.length; i+=2) {
  57. String formVal = MM_fields[i+1];
  58. String elem;
  59. java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_columns[i+1],",");
  60. String delim = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
  61. String altVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
  62. String emptyVal = ((elem = (String)tokens.nextToken()) != null && elem.compareTo("none")!=0)?elem:"";
  63. if (formVal.length() == 0) {
  64. formVal = emptyVal;
  65. } else {
  66. if (altVal.length() != 0) {
  67. formVal = altVal;
  68. } else if (delim.compareTo("'") == 0) { // escape quotes
  69. StringBuffer escQuotes = new StringBuffer(formVal);
  70. for (int j=0; j < escQuotes.length(); j++)
  71. if (escQuotes.charAt(j) == '\'') escQuotes.insert(j++,'\'');
  72. formVal = "'" + escQuotes + "'";
  73. } else {
  74. formVal = delim + formVal + delim;
  75. }
  76. }
  77. MM_tableValues.append((i!=0)?",":"").append(MM_columns[i]);
  78. MM_dbValues.append((i!=0)?",":"").append(formVal);
  79. }
  80. MM_editQuery = new StringBuffer("insert into " + MM_editTable);
  81. MM_editQuery.append(" (").append(MM_tableValues.toString()).append(") values (");
  82. MM_editQuery.append(MM_dbValues.toString()).append(")");
  83. if (!MM_abortEdit) {
  84. // finish the sql and execute it
  85. Driver MM_driver = (Driver)Class.forName(MM_editDriver).newInstance();
  86. Connection MM_connection = DriverManager.getConnection(MM_editConnection,MM_editUserName,MM_editPassword);
  87. PreparedStatement MM_editStatement = MM_connection.prepareStatement(MM_editQuery.toString());
  88. MM_editStatement.executeUpdate();
  89. MM_connection.close();
  90. // redirect with URL parameters
  91. if (MM_editRedirectUrl.length() != 0) {
  92. response.sendRedirect(response.encodeRedirectURL(MM_editRedirectUrl));
  93. return;
  94. }
  95. }
  96. }
  97. %>
  98. <%
  99. Driver DriveraddressData = (Driver)Class.forName(MM_jimi_DRIVER).newInstance();
  100. Connection ConnaddressData = DriverManager.getConnection(MM_jimi_STRING,MM_jimi_USERNAME,MM_jimi_PASSWORD);
  101. PreparedStatement StatementaddressData = ConnaddressData.prepareStatement("SELECT * FROM address");
  102. ResultSet addressData = StatementaddressData.executeQuery();
  103. boolean addressData_isEmpty = !addressData.next();
  104. boolean addressData_hasData = !addressData_isEmpty;
  105. Object addressData_data;
  106. int addressData_numRows = 0;
  107. %>
  108. <html>
  109. <head>
  110. <title>Test Document 2</title>
  111. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  112. </head>
  113. <body>
  114. </body>
  115. </html>
  116. <%
  117. addressData.close();
  118. StatementaddressData.close();
  119. ConnaddressData.close();
  120. %>