· 9 years ago · Dec 02, 2016, 08:40 PM
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<%@page import="edu.southeasttech.stratmeyer.*"%>
3
4<%@page import="java.util.*"%>
5<%@page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
6
7<html>
8<head>
9<title>Display All Records using ArrayList</title>
10<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
11<meta name="GENERATOR"
12 content="IBM Websphere Development Studio Client Advanced Edition for iSeries">
13</head>
14<body>
15 <%
16 String output = ""; //create String object to place output information in
17
18 ProductDB productDB = new ProductDB(); //create a new ProductDB object by calling its default constructor method
19
20 //get an ArrayList with all the product objects - records in it by calling the getProducts() method in the productDB object
21 ArrayList<Product> products = productDB.getProducts();
22
23 if (products == null) {
24 output += "Error! Unable to get products."; //here if getProducts() method returned a null
25 } else { //here if prouducts object not a null - i.e., an ArrayList<> was returned rather than a null
26 output = "<h3>Number of records in ArrayList object = " + products.size() + "</h3>"; //display number of objects in ArrayList<> object
27 Product p = null; //declare a null Product object to be used in for loop for temporarily storing Product objects in ArrayList<> object
28 for (int i = 0; i < products.size(); i++) {
29 p = (Product) products.get(i); //get index i Product object from ArrayList<> (note "i" will be between 0 and products.size())
30 output += p.toString() + "<br />"; //concatenate current output String with properties (database record) from p object
31 }
32 }
33
34 out.print(output); //display either Error report from above or concatenated String with all the records from the ArrayList<>
35 %>
36
37 <p>
38 <a href="index.html">Back to Home</a><br>
39 </p>
40
41</body>
42</html>
43<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><%@page
44 language="java" contentType="text/html; charset=ISO-8859-1"
45 pageEncoding="ISO-8859-1"%>
46
47 <%@page import="edu.southeasttech.stratmeyer.*"%>
48
49<html>
50<head>
51<title>DisplayOne</title>
52<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
53</head>
54<body>
55
56<form action = "DisplayOne.jsp" >
57Primary Key: <input type="text" name="primaryKey" size="20"><br>
58<br>
59<input type="submit" name="submitPrimaryKey" value="SUBMIT">
60<br></form>
61<br>
62<p><a href="index.html">Back to Home</a><br></p>
63
64<%
65
66String input = request.getParameter("primaryKey");
67String output = "";
68
69//out.print("input now = " + input + "<br /> <br />");
70if ( (input != null)&& !input.equals("") ) //user validation
71{
72 ProductDB productDB = new ProductDB(); //create a ProductDB object so that we can dynamically call methods in it
73
74 //test getProduct( ) method
75 Product product = productDB.getProduct(input); //call getProduct() method in productDB object & pass it the primary key
76
77 if(product == null) //test to see if record is found (or SQL error)- i.e. a null was returned
78 {
79 output = "Product " + input + " NOT Found";
80 }
81 else
82 { //here if a valid product object was returned by getProduct( )
83
84 output = "<h3>OUTPUT FROM getProduct(" + input + ")</h3>"
85 + product.toString()
86 + "<br><br><br>";
87 }
88 }
89 else{
90 output = "Please enter a Product Code";
91 }
92
93 out.print(output);
94
95 %>
96
97</body>
98</html>
99<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
100
101
102<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/AJAX_Template.dwt" codeOutsideHTMLIsLocked="false" -->
103<head>
104<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
105
106
107<!-- InstanceBeginEditable name="doctitle" -->
108<title>Eric Stratmeyer</title>
109<!-- InstanceEndEditable -->
110<!-- InstanceBeginEditable name="head" -->
111<style type="text/css">
112.container .content .displayAll {
113 text-align: center;
114}
115.container .content {
116 text-align: center;
117}
118</style>
119<!-- InstanceEndEditable -->
120<style type="text/css">
121<!--
122body {
123 font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
124 background-color: #4E5869;
125 margin: 0;
126 padding: 0;
127 color: #000;
128}
129
130/* ~~ Element/tag selectors ~~ */
131ul, ol, dl { /* Due to variations between browsers, it's best practices to zero padding and margin on lists. For consistency, you can either specify the amounts you want here, or on the list items (LI, DT, DD) they contain. Remember that what you do here will cascade to the .nav list unless you write a more specific selector. */
132 padding: 0;
133 margin: 0;
134}
135h1, h2, h3, h4, h5, h6, p {
136 margin-top: 0; /* removing the top margin gets around an issue where margins can escape from their containing div. The remaining bottom margin will hold it away from any elements that follow. */
137 padding-right: 15px;
138 padding-left: 15px; /* adding the padding to the sides of the elements within the divs, instead of the divs themselves, gets rid of any box model math. A nested div with side padding can also be used as an alternate method. */
139}
140a img { /* this selector removes the default blue border displayed in some browsers around an image when it is surrounded by a link */
141 border: none;
142}
143
144/* ~~ Styling for your site's links must remain in this order - including the group of selectors that create the hover effect. ~~ */
145a:link {
146 color:#414958;
147 text-decoration: underline; /* unless you style your links to look extremely unique, it's best to provide underlines for quick visual identification */
148}
149a:visited {
150 color: #4E5869;
151 text-decoration: underline;
152}
153a:hover, a:active, a:focus { /* this group of selectors will give a keyboard navigator the same hover experience as the person using a mouse. */
154 text-decoration: none;
155}
156
157/* ~~ this container surrounds all other divs giving them their percentage-based width ~~ */
158.container {
159 width: 60%;
160 /*max-width: 1260px;*//* a max-width may be desirable to keep this layout from getting too wide on a large monitor. This keeps line length more readable. IE6 does not respect this declaration. */
161 /*min-width: 780px;*//* a min-width may be desirable to keep this layout from getting too narrow. This keeps line length more readable in the side columns. IE6 does not respect this declaration. */
162 background-color: #FFF;
163 margin: 0 auto; /* the auto value on the sides, coupled with the width, centers the layout. It is not needed if you set the .container's width to 100%. */
164}
165
166/* ~~the header is not given a width. It will extend the full width of your layout. It contains an image placeholder that should be replaced with your own linked logo~~ */
167.header {
168 background-color: #6F7D94;
169 text-align: center;
170}
171
172/* ~~ This is the layout information. ~~
173
1741) Padding is only placed on the top and/or bottom of the div. The elements within this div have padding on their sides. This saves you from any "box model math". Keep in mind, if you add any side padding or border to the div itself, it will be added to the width you define to create the *total* width. You may also choose to remove the padding on the element in the div and place a second div within it with no width and the padding necessary for your design.
175
176*/
177.content {
178 padding: 10px 0;
179}
180
181/* ~~ This grouped selector gives the lists in the .content area space ~~ */
182.content ul, .content ol {
183 padding: 0 15px 15px 40px; /* this padding mirrors the right padding in the headings and paragraph rule above. Padding was placed on the bottom for space between other elements on the lists and on the left to create the indention. These may be adjusted as you wish. */
184}
185
186/* ~~ The footer ~~ */
187.footer {
188 padding: 10px 0;
189 background-color: #6F7D94;
190}
191
192/* ~~ miscellaneous float/clear classes ~~ */
193.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
194 float: right;
195 margin-left: 8px;
196}
197.fltlft { /* this class can be used to float an element left in your page. The floated element must precede the element it should be next to on the page. */
198 float: left;
199 margin-right: 8px;
200}
201.clearfloat { /* this class can be placed on a <br /> or empty div as the final element following the last floated div (within the #container) if the #footer is removed or taken out of the #container */
202 clear:both;
203 height:0;
204 font-size: 1px;
205 line-height: 0px;
206}
207-->
208</style></head>
209
210<body>
211
212<div class="container">
213 <div class="header">
214 <h2>Murach DB Application</h2>
215 <h2> 3 Tier Website</h2>
216 <!-- end .header --></div>
217 <div class="content"><!-- InstanceBeginEditable name="Content" -->
218
219 <form action="DisplayOne.jsp"><input type="submit" name="displayOneRecord" value="Display One Record" /></form>
220<form action="DisplayAll.jsp"><input type="submit" name="displayAll" value="Display All Records" /></form>
221<form action="AddRecord.jsp"><input type="submit" name="addRecord" value="Add a Record" /></form>
222<form action="DeleteRecord.jsp"><input type="submit" name="deleteRecord" value="Delete a Record" /></form>
223<form action="UpdateRecord.jsp"><input type="submit" name="updateRecord" value="Update a Record" />
224</form>
225
226 <!-- InstanceEndEditable --><!-- end .content --></div>
227 <div class="footer">
228 <p>©2014 by Southeast Tech Staff</p>
229 <!-- end .footer --></div>
230 <!-- end .container --></div>
231</body>
232<!-- InstanceEnd --></html>
233<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
234<%@page import="edu.southeasttech.stratmeyer.*"%>
235<%@page language="java" contentType="text/html; charset=ISO-8859-1"
236 pageEncoding="ISO-8859-1"%>
237
238
239<html>
240<head>
241<title>Add a Record</title>
242<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
243<meta name="GENERATOR"
244 content="IBM Websphere Development Studio Client Advanced Edition for iSeries">
245</head>
246<body>
247
248 <form action = "AddRecord.jsp">
249 Code: <input type="text" name="code" size="20"> <br>Description:
250 <input type="text" name="description" size="40"> <br>Price:
251 <input type="text" name="price" size="20"><br> <br>
252 <input type="submit" name="submit" value="ADD Record">
253 </form>
254
255 <p>
256 <a href="index.html">Back to Home</a><br>
257 </p> <p></p>
258 <%
259 String aCode = request.getParameter("code");
260 String aDescription = request.getParameter("description");
261 String aPrice = request.getParameter("price");
262
263 String output = "";
264 //test that it's not the first time (html form not submitted) && that data is entered in all fields
265 if (aCode != null && !aCode.equals("") && !aDescription.equals("")
266 && !aPrice.equals("")) {
267 try {
268 double dblPrice = Double.parseDouble(aPrice);
269
270 output = "<h3>OUTPUT FROM addProduct( ) method</h3>";
271 Product newProduct = new Product(aCode, aDescription,
272 dblPrice);
273
274 ProductDB productDB = new ProductDB(); //ProductDB methods are no longer static methods,
275 // so need to create a ProductDB object
276
277 //note - addProduct returns a false if newProduct already in DB
278 boolean boolAdd = productDB.addProduct(newProduct);
279 if (boolAdd) //check to see if product was sucessfully added
280 {
281 output += aCode + " record sucessfully added<br><br>";
282 } else {
283 output += "Error: " + aCode
284 + " record already exists in DB<br><br>";
285 }
286 }catch (NumberFormatException err)
287 {
288 output += "Please enter a valid number in your price textfield: " + aPrice;
289 }
290 catch (Exception e) {
291 output += "Error: " + e.toString();
292 }
293 } else {
294 output = "Please enter a product code, description and a price: ";
295 }
296
297 out.print(output);
298 %>
299
300
301</body>
302</html>
303<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
304<%@page language="java" contentType="text/html; charset=ISO-8859-1"
305 pageEncoding="ISO-8859-1"%>
306
307<%@page import="edu.southeasttech.stratmeyer.*"%>
308<html>
309<head>
310<title>Delete a Record</title>
311<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
312<meta name="GENERATOR"
313 content="IBM Websphere Development Studio Client Advanced Edition for iSeries">
314</head>
315<body>
316 <form action="DeleteRecord.jsp">
317 Primary Key: <input type="text" name="primaryKey" size="20"><br>
318 <br> <input type="submit" name="submitPrimaryKey"
319 value="DELETE Record"> <br>
320 </form>
321 <br>
322 <p>
323 <a href="index.html">Back to Home</a><br>
324 </p>
325
326 <%
327 String input = request.getParameter("primaryKey");
328 String output = "";
329 ProductDB productDB = new ProductDB(); //created a ProductDB object to allow calling "dynamic/non-static" methods
330 out.print(productDB.connect()); //Display result of trying to connect to database
331 //out.print("User entered: " + input);
332 if (input != null && input.length() == 4) {
333 Product productInput = productDB.getProduct(input);
334 if (productInput != null) {
335
336 //create a Product object with the input String as its code/primary key
337 //using one of the parametized constructor methods
338 output += "<h3>OUTPUT FROM deleteProduct( ) method </h3>";
339 boolean boolDel = productDB.deleteProduct(productInput); //returns true if able to delete record or if not in database
340 if (boolDel) //check to see if product deleted successfully
341 {
342 output += input
343 + " deleted from DB or not in the database table"
344 + "<br><br><br>";
345 } else {
346 output += "Error: could not delete " + input;
347 }
348 } else {
349 output += input + " not in database";
350 }
351 } else {
352 output += "Please enter a valid Primary Key with 4 characters";
353 }
354
355 out.print(output);
356 %>
357
358
359</body>
360</html>
361<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
362<%@page language="java" contentType="text/html; charset=ISO-8859-1"
363 pageEncoding="ISO-8859-1"%>
364
365<%@page import="edu.southeasttech.stratmeyer.*"%>
366
367<html>
368<head>
369<title>Update a Record</title>
370<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
371</head>
372<body>
373 <form action="UpdateRecord.jsp">
374 Primary Key: <input type="text" name="primaryKey" size="20"><br>
375 <br> <input type="submit" name="submit"
376 value="FIND RECORD TO UPDATE"> <br>
377 </form>
378 <br>
379 <p>
380 <a href="index.html">Back to Home</a><br>
381 </p>
382
383 <%
384 String input = request.getParameter("primaryKey");
385
386 if (input != null && !input.equals("")) {
387 ProductDB productDB = new ProductDB();
388
389 //test getProduct( ) method
390 Product product = productDB.getProduct(input);
391 //Note - getProduct( ) method returns a null if either the record not found OR if SQL Error
392 if (product != null) { //Here if a product object returned by the getProduct( ) method
393 %>
394
395 <form action="UpdateRecordSubmit.jsp">
396 <b>Code: <%=product.getCode()%></b><br /> <input type="hidden"
397 name="code" value="<%=product.getCode()%>"> Description: <input
398 type="text" name="description" size="20"
399 value="<%=product.getDescription()%>"><br>Price: <input
400 type="text" name="price" size="20" value="<%=product.getPrice()%>"><br>
401 <br> <br> Please modify above information if necessary and
402 then click on Update Record button<br>
403 <input type="submit" name="submit" value="Update Record">
404 </form>
405 <%
406 } else { //NOTE - also here if SQL error when running the getProduct() method, but we'll assume that method is good
407 out.print("Product with product code: " + input
408 + " not found.");
409 }
410
411 } else {
412 out.print("Please enter a 4 character primary key");
413 }
414 %>
415</body>
416</html>
417<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
418<%@page language="java" contentType="text/html; charset=ISO-8859-1"
419 pageEncoding="ISO-8859-1"%>
420
421<%@page import="edu.southeasttech.stratmeyer.*"%>
422
423<html>
424<head>
425<title>Update a Record</title>
426<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
427<meta name="GENERATOR"
428 content="IBM Websphere Development Studio Client Advanced Edition for iSeries">
429</head>
430<body>
431
432 <%
433 //get latest updated information
434 String aCode = request.getParameter("code");
435 String aDescription = request.getParameter("description");
436 String aPrice = request.getParameter("price");
437 String aSubmit = request.getParameter("submit");
438
439 String output = "";
440 Product newProduct = null;
441
442 if (aSubmit.equals("Update Record")) {
443
444 try {
445 double dblPrice = Double.parseDouble(aPrice);
446
447 output = "<h3>OUTPUT FROM updateProduct( ) method</h3>";
448 newProduct = new Product(aCode, aDescription, dblPrice);
449 ProductDB newProductDB = new ProductDB();
450
451 //note - addProduct returns a false if newProduct already in DB
452 boolean boolAdd = newProductDB.updateProduct(newProduct);
453 if (boolAdd) //check to see if product was sucessfully updated
454 {
455 output += aCode
456 + " record successfully updated<br><br>";
457 } else {
458 output += "Error: " + aCode
459 + " unable to update record in DB<br><br>";
460 }
461 } catch (Exception e) {
462 output += "Error: " + e.toString();
463 }
464 }
465 out.print(output);
466 %>
467
468
469 <br>
470 <p>
471 <a href="index.html">Back to Home</a><br>
472 </p>
473
474
475</body>
476</html>