My responsibility is to add new requirements to make your work challenging (but not tedious). With your help in class on May 12th, I have come up with the following list of requirements for Phase II:
Examples of all the above requirements are here (though they should be made better where appropriate): |
|
|
|
|
|
|
|
|
|
|
|
Of course, some of your reports will end up longer than the examples, but the examples show you the kind of data I expect for each report (your particular data choices can be different). Remember that you only have to code the header row and one row of the detail because you will put your format in a loop that the Java Server Page will fill with your SQL Command (query) results.
To make our database work for everyone, I am requesting that you use the database field names as the NAME attribute values within your form control elements. For example, in your New Customer Form, you would have an INPUT element that looks like this:
<INPUT TYPE=TEXT NAME=Name>
because I have documented the name in the Manufacture Data Definition SQL Commands document that the Customer table field for name is named Name. Creating your forms for requirements 1, 2, 3, 4, 5, and 6 above should be easy if you just create an input control for each field in the respective tables (of course you can add additional information in the forms that just won't be saved in the tables).
<FORM ACTION="http://www.cev.washington.edu/498/addmaterial.jsp" method=GET>
The ACTION attribute points to the URL where the FORM can be processed by a Java Server Page (JSP). You will be writing the main JSP processing for your form and reports. So, to make that work correctly, you will have to point to the right servlet for each form and report. You will see a table of proper servlet names to use later in this document. I will differentiate between student forms through an INPUT element that you should include immediately after each open FORM tag. In the case of my addmaterial.html form, you see:
<INPUT NAME=author TYPE=HIDDEN VALUE=bdc>
I set the VALUE attribute to my assigned initials, brc. You should set all your hidden INPUT element VALUE attributes to your assigned initials (even HIDDEN control types pass the named variable to the JSP).
<%@ page contentType="text/html;charset=ISO-8859-1" language="java" import="javax.naming.*" import="javax.sql.*" %> <HTML> <HEAD> <TITLE>Successful Add to Add Show Table</TITLE> <META content="text/html; charset=unicode" http-equiv=Content-Type> </HEAD> <body> <% // Obtain our environment naming context Context initContext = new InitialContext(); // Look up our data source DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/manufacture"); // Allocate and use a connection from the pool java.sql.Connection conn = ds.getConnection(); // create and execute the query java.sql.Statement stmt = conn.createStatement(); java.sql.ResultSet rs = null; String error="Successful Add of New Material"; String new_id="-1"; try { rs = stmt.executeQuery("SELECT MAX(Material_ID) AS MAX_ID FROM Material"); if (rs.next()) { new_id = "" + (rs.getInt(1)+1); } else { new_id = "0"; } rs.close(); //create new set here stmt.executeUpdate("INSERT INTO Material VALUES (" + new_id + "," + request.getParameter("OnHand") + "," + request.getParameter("LeadTime") + "," + request.getParameter("Unit") + ",'brc')"); } catch (Exception exp) { error = exp.toString(); } stmt.close(); conn.close(); %> <!-- Put your visual HTML body content here --> <H3><%= error %></H3> </BODY> </HTML>Don't panic if this looks completely foreign to you. Just think it through with me here. Remember that a CGI script can connect a Web server to a database and execute SQL commands through a database interface. We just happen to be using Java as our CGI language to make the connection. So, by the time your code runs, the Java has already connected to the database, created a valid Statement object (referenced by the stmt for which our executeUpdate() routine will run. Now the CGI code must also be able to get the data from our form into the database. With Java, we can use the getParameter() method that is available from the JSP request object (which is created automatially by the Java Server Page engine running on the server). So, all you have to do is use the request.getParameter() routine to process each value from your form and put its value into the SQL command that will add a new record to the table you wish to append. Any other text you need between the form data you can put together using the + operator (the + operator in Java is called a concatenation operator when you are using text values (called Strings)).
Look closely at where the quotes (single and double) are placed in the INSERT statement. The single quotes are passed to the database to properly identify text and date fields (remember text and dates need to be enclosed in single quotes). Now try doing some simple substitutions with me. Imagine a purchasing employee filled out an Add New Material Form on the Web. The form included INPUT controls with the following NAME attributes and control contents:
NAME | CONTENT |
---|---|
OnHand | 4 |
LeadTime | 14 |
Unit | 0 |
Owner | brc |
INSERT INTO Material VALUES (47,4,14,4,'brc')
to the database. Since the command is a valid command, the record is gladly added to the database. You should write 5 similar stmt.executeUpdate() commands for your other five forms and save them in 5 separate files. Then, upload your files to your directory on sambucus.cev.washington.edu with the following names:
FORM | File Name |
---|---|
New Customer | addcustomer_xxx.jsp |
New Product | addproduct_xxx.jsp |
New Production | addproduction_xxx.jsp |
New ProductSale | addproductsale_xxx.jsp |
New MaterialPurchase | addmaterialpurchase_xxx.jsp |
For your HTML, upload the following HTML file names to the subdiretory with your initials (and use the respective URL in your forms):
FORM | File Name | URL |
---|---|---|
New Customer | addcustomer.html | http://www.cev.washington.edu/498a/xxx/addcustomer_xxx.jsp |
New Feedback | addproduct.html | http://www.cev.washington.edu/498a/xxx/addproduct_xxx.jsp |
New Transport | addproduction.html | http://www.cev.washington.edu/498a/xxx/addproduction_xxx.jsp |
New Trip | addproductsale.html | http://www.cev.washington.edu/498a/xxx/addproductsale_xxx.jsp |
New Location | addmaterialpurchase.html | http://www.cev.washington.edu/498a/xxx/addmaterialpurchase_xxx.jsp |
If you do this correctly, your form will be processed by your SQL function as intended. If you do it wrong, I will send you an e-mail message explaining what is wrong and how to correct it. I will have to accept whatever you haven't gotten working as your final (and you will have had to make a good effort by midnight on June 7th).
REPORT | File Name | URL |
---|---|---|
Product Profit | prodprof_xxx.jsp | http://www.cev.washington.edu/498a/xxx/prodprof_xxx.jsp |
Customer Buying History | custbuy_xxx.jsp | http://www.cev.washington.edu/498a/xxx/custbuy_xxx.jsp |
Quality Index by Supplier | qualsupp_xxx.jsp | http://www.cev.washington.edu/498a/xxx/qualsupp_xxx.jsp |
Raw Materials Inventory | matinv_xxx.jsp | http://www.cev.washington.edu/498a/xxx/matinv_xxx.jsp |
Your Specified | other_xxx.jsp | http://www.cev.washington.edu/498a/xxx/other_xxx.jsp |
Reports are generated similarly to the SELECT command results Java code we reviewed together in class (and which you can always review in the SQL Starter Kit document). To generate a report you create a hyperlink in your HTML document that points to a valid URL for the proper JSP to run. For example, for my Product Profit Report, I would create an A element like the following:
<A href=http://www.cev.washington.edu/498/prodprof_brc.jsp>
You can put all of your report hyperlinks on your home page or you can put them on other pages within your site if you prefer. But, I will need to find them easily when reviewing your site in order to grade them as best as you will want me to. When someone clicks on a hyperlink like the example, the Java Server Page engine on the class Web server will handle the request as the JSP named prodprof_brc.jsp.
Your text files should look something like the following example from last year:
<%@ page contentType="text/html;charset=ISO-8859-1" language="java" import="javax.naming.*" import="javax.sql.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>WOW - Entertainment Venue Planning</title> <% // Obtain our environment naming context Context initContext = new InitialContext(); // Look up our data source DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/entertain"); // Allocate and use a connection from the pool java.sql.Connection conn = ds.getConnection(); // create and execute the query java.sql.Statement stmt = conn.createStatement(); java.sql.ResultSet rs = null; String error=""; %> </head> <BODY BGCOLOR="#B1AD9C" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0"> <CENTER> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TD WIDTH="25"><IMG SRC="../498a/atl/images/navarrow.gif" title="arrow"></td> <TD WIDTH="150"><img src="../498a/atl/images/navigation.jpg" title="Navigation"></td> <TD WIDTH="575" ROWSPAN="7" valign="top" align="left"> <DIV CLASS="white_border"> <DIV CLASS="white_border_text"> <font size="+1">All Shows Report</font> <p> <center> <table border="0" cellpadding="3" cellspacing="0"> <tr> <td colspan="6" align="center" bgcolor="5B0110"><font color="#eeeeee"><b>Reports for All Shows</b></font></td> </tr> <tr bgcolor="#eeeeee"> <td width="80">Show ID</td> <td width="120">Entertainer</td> <td width="120">Venue</td> <td width="80">Date</td> <td width="80">Time</td> <td width="80">Price</td> </tr> <% try { rs = stmt.executeQuery("SELECT Show_ID, Entertainer_FK AS eName, Venue_FK AS vName, Date, Start_time, Ticket_Price FROM Show WHERE Owner='498'"); while(rs.next()) { String show_id = rs.getString("Show_ID"); String entertainer_id = rs.getString("eName"); String venue = rs.getString("vname"); String date =rs.getString("Date"); String time =rs.getString("Start_time"); String price =rs.getString("Ticket_price"); int time_digit = Integer.parseInt(time); if((time_digit<12 && time_digit>0) || (time_digit==24)) time = time_digit + ":00am"; else if(time_digit>=12 && time_digit<=23) time = (time_digit-12) + ":00pm"; %> <TR> <TD><%= show_id %></TD> <TD><%= entertainer_id %></TD> <TD><%= venue %></TD> <TD><%= date %></TD> <TD><%= time %></TD> <TD>$<%= price %></TD> </TR> <% } } catch (Exception exp) { error = exp.toString(); } rs.close(); stmt.close(); conn.close(); %> </TABLE> <H3><%= error %></H3> </center> <br> </DIV> </DIV></TD> </TR> </TABLE> </CENTER> </BODY> </HTML>
Note the Java basically mixes your HTML tags with the results from your SQL SELECT command. Spend some time thinking this through. Print the code out and use highlighters to mark the parts that are HTML and the parts that come from the Java Servlet technology. Compare mixing SQL results and HTML tags using the CGI with mixing XML data and HTML tags using XSLT.