Professor Ted Markowitz
233 Buckman Hall
Tagliatela College of Engineering


Winter 2010 - CS441/CS655: Web-Database Application Development - Assignments




List of Assignments
NUMBER DUE DATE TASK
1 01/15/10

Readings:

Tasks:

For all the following software installations please see the Software instructions section on the class website for the details on downloading and proper installation. Contact me via e-mail (cs441@unh-ececs.net) should you run into any problems.

  1. Install Firefox 3.x (if necessary)

    • Install Firefox Add-on Web Developer
    • Install Firefox Add-on Live HTTP Headers
    • Install Firefox Add-on FireBug
    • Install Firefox Add-on FireFTP (optional)
    • Install Firefox Add-on Screengrab (optional)
  2. Install the latest NetBeans IDE (and Java JDK, if required) on your system. Don't forget to click on 'Customize' to make sure that Apache Tomcat is installed as well. This is critical so that you can do Java Servlet and JSP programming later on.

  3. When NetBeans has been installed, first click on 'Help => Check for Updates' to make sure NetBeans is up-to-date.

  4. Watch the Introduction to Creating Java Applications video.

  5. Then follow the NetBeans IDE Java Quickstart on-line tutorial to create your own NetBeans Java project based on what you just viewed. Don't be afraid to add some extra Java code to your project for practice.

  6. After you successfully run HelloWorldApp, go to the 'Output HelloWorldApp (run)' panel in NetBeans, right-click on it and select 'Save As...' from the pop-up menu. Save the runtime output somewhere as 'hwrun.log'.

  7. Upload a copy of the output log file to your FTP account directory labeled "assignment-1" before the next session.
2 01/22/10

Readings:

  • Chapter 3 in Parsons book
  • Read Sections 4, 5, and 6 in IETF RFC 2616 (http://www.ietf.org/rfc/rfc2616.txt) which is the one that defines HTTP 1.1 to get a more detailed idea of how HTTP works and what RFC's contain in general. It's good to know where to find these technical documents and how they are structured when you need details on how things work on the Internet and the web.

Tasks:

In this assignment we are going to examine how a VERY simple HTTP server with the capability for running pre-compiled Java Servlets (Java server-side programs that can be used to produce dynamically generated content) works. This server is extremely simplistic, but it is able to respond to HTTP GET requests for any static HTML files found in its '/webroot' directory as well as being able to run any Java Servlets which have been compiled into classes and placed in that same location. This is the essence of a Web Server/Servlet Container application such as Apache Tomcat.

  1. First, before starting up NetBeans, please make sure you can find the project directory on your machine where NetBeans holds all your NetBeans project files. On my Linux system this is called NetBeansProjects in my home directory (on a Windows system this is most likely somewhere under "C:\Documents and Settings\xxx'" where 'xxx' is your Windows username). When you create new projects (using 'File->New Project' on the main NetBeans menu or by hitting Ctrl+Shift-N, for example) this is the directory shown as the 'Project Location:' when filling in the project details on the 'New Project' panels. This is also the directory where your HelloWorld project from Assignment #1 should be found.

  2. Once you've located this directory, download the simple HTTP Server and Servlet Container project compressed ZIP file to your system and place the .zip file in your NetBeans project directory as described in Step 1.

  3. Unzip the HowWebServersWork.zip file right into this same directory. It will create a full HowWebServersWork project directory structure in your main project folder. You can use Winzip (www.winzip.com) or any other ZIP program of your choice to decompress the zipped file.

  4. Now, start up NetBeans as usual.

  5. Go to 'File->Open Project' or use Ctrl+Shift-O to open the now unzipped project in NetBeans. Make sure you are looking in the correct directory, again in my case that is NetBeansProjects. You should see the project labeled HowWebServersWork in your projects directory.

  6. Click on HowWebServersWork to select the project and hit the 'Open Project' button. You should see the web server project in the 'Projects' panel in the upper-left corner of the NetBeans window.

  7. Double-click on the project's name and it will open to show you all the source files, libraries (servlet.jar and the JDK), and folders containing any test files (there are no test files in this project). The HTML files and compiled Servlet class files we'll be working with are in the project's "webroot" directory.

  8. Keep double-clicking on the Source Packages till you see the .java files in the HowWebServersWork package. Read through all of the .java files in the project to get a feel of how this simple HTTP server handles requests and responses, and what a trivial Java Servlet looks like.

  9. Now we're ready to run our toy HTTP Server/Servlet Container, which can both GET files and execute pre-compiled Java Servlets. NOTE: Both .html files and compiled Java Servlet .class files must be located in the project's "webroot" directory for this server to find them properly. On my system this directory is called, NetBeansProjects/HowWebServersWork/webroot.

  10. You'll find several .html files (including 'index.html', which is the default file retrieved when the URL you input to your browser is simply 'http:/localhost:XXXX/' --- [Note: 'XXXX' is the port number that your HTTP server is listening on for HTTP Requests.] Any HTML files you place in the "webroot" directory can be served up by your simple server.

    NOTE: You'll have to find the port # the web server is currently using by reading through the .java files carefully in the project. You'll also find a few .class files in that same 'webroot' directory, which are compiled Java Servlets. These .class files are ready to be executed by our simple web server. One servlet is not called directly by the user (that's ErrorServlet which informs the user about servlet errors), but the other, PoeticServlet, can be requested as part of a URL. More on that a little later however.

  11. Since this project has already been built (normally you'd do 'Build Main Project' (F11) to compile and link everything before it is runnable), you only need to execute 'Run Main Project' (or use F6 or click on the right green-arrow icon on the main toolbar or the double green-arrow icon left of the 'Output' panel at the bottom of the NetBeans window) to get the HTTP server running on your system. Once running, the server can be stopped by hitting the small red button icon to the left of the Output panel.

  12. Now run the HTTP server main program, SimpleWebServer, as described in the previous step. In the Output panel at the bottom of the window you will see:

    init:
    deps-jar:
    compile:
    run:
    Simple HTTP Server listening for requests...

    and the double green-arrow next to the text will now be grayed-out with the red 'stop running' icon directly below it now activated. You can click on this icon to halt the running program.


  13. Open your Firefox browser and from the main 'Tools' menu, select the 'Live HTTP headers' add-on you'd previously installed. This will open a separate 'Live HTTP headers' window. Keep this window open and watch the HTTP conversation in the background as you do the rest of this exercise. This add-on will automatically capture all the HTTP communications from this point on till you save it away as a file that you will submit as part of the assignment later on. You may be surprised by exactly what is being transmitted and received by your browser depending on what else it happens to be doing at the time.

  14. In your browser's address (URL) input area enter 'http://localhost:XXXX/' (remember 'XXXX' is the port number that the server is using for incoming requests). At this point you will see the default 'index.html' page used by our example web site. Capture what it says with a screenshot of the browser's window and submit that image file as part of Assignment #2. Most OS's can make use of the "PrtSc" (Print Screen) key on your keyboard to capture an image of the screen. Alternatively, you can add the Firefox Screengrab! add-on to your Firefox browser. This can be used to capture any output shown in the browser window.

  15. Now try entering a nonexistant URL, e.g., 'foo.html' (that is, one not in the 'webroot' directory). Take note of the HTTP response in the Live HTTP headers window.

  16. Now run the servlet named, PoeticServlet, using the convention that all our servlets are accessed using an URL that looks like the following:

    http://localhost:XXXX/servlets/YYYYYYYY

    where 'YYYYYYYY' is the name of the servlet. Take a screenshot of the page generated by the servlet. You should upload this image file to Assignment #2 when you are done.

  17. Before leaving this servlet's dynamically generated page, use the Web Developer Firefox add-on you installed to view the page's generated source. From the main Firefox 'Tools' menu select 'Web Developer->View Source->View Generated Source' to see exactly what the servlet generated compared to what is in the .java file in the project directory. The Web Developer toolbar should also be visible right above the main browser window and can also be used to get to the same functionality. If the toolbar's not visible, use 'View->Toolbars->Web Developer Toolbar' to expose it. When the Web Developer window with the generated source appears, save it to a file using 'File->Save Page As...' and submit that file as part of Assignment #2.

  18. You can also pass a special parameter as part of the URL to tell this server to shut itself down. You need to read through the source code carefully to find the magic word which shuts down the server. When you're ready to quit, enter the following URL into the browser's address input area, "http://localhost:XXXX/magicword", where "magicword" is the special shutdown command you discovered in the source files. Check the NetBeans Output panel and you'll see that the server has indeed terminated. Right-click on the NetBeans Output panel and use "Save as..." to save the entire console output for your web server into an external file. Submit this file as part of Assignment #2.

  19. Lastly, in the Live HTTP header window, which has been capturing all the HTTP conversations between your browser and the servers it has communicated with, click on the 'Save All...' button to save the log as an external file. Read over this file to get a better feel for the conversation between a browser and a server and then upload it and all the other output files for Assignment #2 mentioned previously to the class FTP server, placing them in the assignment-2 subdirectory.

3 01/29/10

Readings:

  • Chapters 3 & 4 in Parsons book

Tasks:

You will begin developing a hands-on understanding of HTML & CSS concepts and syntax by doing the two tutorials listed below. Please go through them completely. We will be reviewing these topics in detail in class.

Finally, I'll be asking you to jump ahead a little bit in the course to get a head start on some of the Java technologies---specifically Servlets and Java Server Pages---that will be the foundation for all our web applications during the semester. Don't worry if you don't yet understand all the concepts included in these Java and Netbeans exercises. They will begin to make more sense as we get further into the Model-View-Controller design pattern and how to apply Servlets and JSP's when architecting systems using MVC. If you'd like, please feel free to read ahead in the text (Chapters 9 & 10 in the Parsons book) for more details on web application development and MVC. I wanted to introduce these ideas to you early in the course to make sure your development environment is set up correctly for the future and to give you a brief taste of one way that web applications can be built in a Java-based environment.

  1. Do the W3Schools HTML Tutorial found at http://www.w3schools.com/html. When done, please take the brief quiz and work through it until you get all the answers correct.
  2. Likewise, please do the W3Schools CSS Tutorial found at http://www.w3schools.com/css and then complete the CSS quiz. Again, make sure you can answer all the questions correctly before continuing.
  3. Review the HTML and CSS examples I've collected for you in the mixed-examples directory to see HTML and CSS in action. Just click on any of the '.html' files you see in the directory listing to pull them up in your browser. You can see the source code in Firefox for any .html file by doing 'View->Page Source' (Ctrl-U) once you've loaded the file into the browser. You can also view the contents of any of the '.css' files by clicking on them as well.
  4. Lastly, complete the Introduction to Developing Web Applications NetBeans tutorial to make sure you're comfortable with setting up a JSP-based web application. Make sure to use the Tomcat Servlet Container in your project. When complete, upload copies of all the .java and .jsp files you created to the class FTP server under 'assignment-3'.
4 02/05/10

Readings:

  • Review Chapter 3 in the Parsons book again to refresh your understanding of HTML concepts.
  • You can refer to the on-line HTML/XHTML reference found here as needed.
  • A brief reference card containing all the core HTML concepts in one spot can also be found here.
  • Many HTML samples can be found in the 'Other Resources' section of the class web server

Tasks:

  • Here are the contents of a browser window that is displaying a single, simple HTML page (i.e., it contains no CSS styling) after it has loaded, but BEFORE the user has interacted with it. Recreate this page using HTML (strict XHTML 1.0 syntax, please), making it look as identical as you can (in every respect, including all the notes you see in the example verbatim) to the screenshot of the browser window you were given. Don't worry if the fonts or the absolute sizes of the text are not exactly the same. Those are browser and user dependent. The relative sizes and placement on the page should be pretty close however. Also, all the hyperlinks and the "Back to class" button should really work. The URI's they're attached to are shown in the PDF example itself.

    You can use any editor you choose that can output plain text files (e.g., Notepad, vi, emacs, MS Word, etc.) to write your HTML. Here is a basic XHTML template you can copy to help you get you started. However, for most students it's suggested that you use the HTML editor built into NetBeans which provides a lot of nice editing features for writing HTML. Just start up NetBeans and then do "File->New File...->Other->XHTML File" to create a new HTML file which uses the XHTML 1.0 Strict DTD. If it's not already showing, make sure you do "Window->Palette" in NetBeans to display the HTML tools widgets. You can drag-and-drop these into your HTML page as needed. This HTML file is the one that you'll load into Firefox using 'File->Open File' to display the page you have created.

  • While you are in the process of writing your page, you should revalidate the HTML in the file as you go using the Firefox Web Developer add-on to make sure it continues to adhere to the XHTML 1.0 strict DTD. From the Web Developer toolbar in Firefox select 'Tools->Validate Local HTML' after you've loaded the latest version of your page into Firefox. Don't forget to reload/refresh the browser page after each set of edits you make to see all the changes added since the last save. Then revalidate. You can also upload your local file by hand to the W3C Markup Validation Service.

    Whichever method you use, your HTML file MUST validate cleanly and completely before uploading the functioning HTML file to the class FTP server under assignment #4. If it doesn't, please edit it again and revalidate it.

    NOTE: Remember that since the DOCTYPE DTD in the template specifies 'strict' XHTML 1.0, the case for all elements must be lower case and every tag must have either a separate terminating tag or be self-terminating as in: <img src="/images/unh-logo-2.gif" alt="UNH Dept. of Electrical & Computer Engineering and Computer Science" />. Pay attention to the "space/" before the closing > in the tag. If you don't do this, then the HTML Validator will flag them as errors.

5 02/12/10

Readings:

  • Read Chapters 9 & 10 in the Parsons book on Web application servers, MVC architecture, Java Servlets, and Java Server Pages (JSP's).

Tasks:

Take your HTML file from Assignment #4 as a starting point. I'd like you to add CSS styling and CSS-style presentation layout to that file to show me that you understand those concepts. Here is what it needs to have done to it at a minimum (you can do much more if you like; I'll be suitably impressed):

  • Using your existing HTML page for basic content, I'd like you to first add basic layout styling to it. It should have a fixed-height header section, a fixed-height footer section, a left-hand fixed-width sidebar column for holding a site navigation menu, and to the right of this navigation sidebar, add a fluid content area. You will be embedding the HTML content from Assignment #4 into this content area.
  • Use this external CSS stylesheet file as a starting point for your own layout. Please feel free to modify it as you see fit. This HTML file uses that exact same layout style (though it's embedded directly into the file's HEAD section) so you can see exactly what it looks like as-is. Many other examples of using CSS can be found here.
  • Modify the current background colors and/or add a background-image to at least one of the main regions on the page you are developing.
  • Give each of the standard HTML header types in your document a style of its own. Color, font, weight, style, size, etc. all can be changed. Use a CSS class selector to do this.
  • Define at least two new class selectors and two new id selectors of your own choosing and use them in your page somewhere. Remember you can style any element on the page including forms and their contents.
  • Define and use a new class selector called 'important' which can be applied only to span or em elements. It should make the text it is styling bold, color the text background red, and the text should be white and monospaced.
  • Style your table's caption and header rows to make them stand out better.
  • Add an image of some sort to the header section along with some styled text describing the page. You can find some free images here. Have the image float to the right side of the browser window and have any text to the left of it.
  • Change the background of all body text to be light grey (e.g., #EEEEEE) and make the body text use a cursive font.
  • Make all the header and footer text use a sans-serif font. The footer text should be half the size of "normal" text.
  • Create a textual menu in the left sidebar with at least 4 links in it (one per line) which point to some other URL's on the web. When you hover over a link in this menu, it should reverse the colors of the text in the link. E.g., if the menu text is white on green, then hovering over the link should make the text green on white.
  • Make sure that in doing this exercise you show examples of using external stylesheets, using an embedded stylesheet, and also use of some inline styles within element tags.

There are many CSS and HTML references on the web. Here are just a few sources for you to use:

IMPORTANT REMINDER: Your 2-page Vision Statement describing the basic concept, contents, and functionality of your Term Project is due next week. The Vision Statement's format is defined here.

6 02/17/10

Readings:

  • Review Chapter 10 in Parsons book to refresh your understanding of servlets, JSP, etc. for this week's tasks shown below.

  • Go to Sun's J2EE Core Patterns page and read the detailed information on (i.e., click on the diagram in the appropriate spot) each of the following Java EE architectural patterns: Front Controller, View Helper, Dispatcher View, Transfer Object and Data Access Object. We've been discussing these ideas as part of explaining the overall MVC JSP Model 2 concept. You will be using some combination of these patterns in the MVC-based design for your Term Project to separate the Model from the View from the Controller components in your final application.

Tasks:

  1. Review all your previous assignments, the readings in the textbook and the other online readings you done thus far, and your lecture notes. The midterm exam will be given during the next session covering everything through the end of Session #6. It will be open book (no electronic devices, please) and should last about 1/2 of the class.

  2. Download the Chapter 10 examples which accompany the Parson's book from this location. These are the sources for the examples and diagrams that you see in Chapter 10. You can certainly download and examine any of the other examples as well, but focus on Chapter 10 to make sure you're comfortable with the basics of Servlets, JSP, and MVC.

  3. Unzip the downloaded Chapter 10 examples file into to your NetBeans project directory and start NetBeans. I've converted all these examples into Netbeans projects so you should be able to load them from inside of NetBeans ("File -> Open Project"). You will find the examples inside of the "Chapter 10" folder in your NetBeans directory.

  4. Open each project in turn, build it, and run it as a Tomcat application (F11 and F6). The running applications should appear in your browser using the URI starting with "http://localhost:8084/" (Note: the port might appear as 8080, depending on how you installed NetBeans). Once you understand how each app acts within the browser, go back to NetBeans and examine the HTML, JSP, and Java sources closely inside the project to see how these components work together. Please go over each one slowly and carefully to make sure you understand as much as possible how the incoming HTTP requests are handled, the webflows are managed, and the responses are being generated. Don't worry if you don't understand ALL the syntax of JSP's and JSTL yet, we'll be covering the details in class. Send me any queries, if you're confused.

  5. Do Exercise 10.1 ('AcceptLanguageServlet') in the Parsons' textbook. Refer to the online Javadocs for details on all the classes and methods supported by the Java API's. Focus particularly on javax.servlet.http and javax.servlet.jsp for information on handling requests and responses using servlets and JSP's.

7 02/24/10

Readings:

  • Review the JSP Introduction lecture notes through to the end.

  • Chapter 12 in the Parsons book on DBMS and JDBC integration with Java web apps

  • Read the SQL refresher document posted on-line at SQL Refresher. We're assuming that you are already familiar with SQL and SQL syntax, so this should be mostly a review exercise.

Tasks:

  1. Run each of the Servlet examples you find here. Please make sure you also view the source code for each to understand how each basically functions.

  2. In the same way, run the JSP examples you find here. While you can surely examine all the examples, please make sure to focus on running and viewing the source code for at least each of the following examples:

    • Basic Arithmetic
    • Basic Comparisons
    • Implicit Objects
    • Functions
    • Numberguess
    • Date
    • Snoop
    • ErrorPage
    • Carts
    • Checkbox
    • Color
    • Calendar
    • Include
    • Forward
    • JSP-Servlet-JSP
    • XML syntax example

  3. Download this version of the Webhomecover application from Chapter 10 to your machine and unzip it into your NetBeans project directory. Start NetBeans and open the project. Your job is to add a new checkbox to the form on the "Buildings Policy Details" page with the label, "Used for business purposes?" If it's checked, then the buildings portion of the final premium quote should be increased by 25%.

    Hint: Run the unzipped project first, before changing anything, and read the sources of each of the files in the NetBeans project window that are being used (including all the .jsp, .htm, and .java files). Look at them one-by-one in the order they are accessed when the application is executing. You will need to modify the "buildings.jsp" view, the "BuildingsDetails.java" bean, and the "InsuranceQuoter.java" business rules file to make this work properly. Look at how the existing form fields are sent from the buildings policy view page through the HTTP request using the BuildingsDetails session-scoped bean and then read from that same session bean by the InsuranceQuoter to calculate the final quote. When your project has been updated with the new functionality, zip it up and upload it to the class FTP server under 'assignment-7'.

  4. The final task is to create the MySQL database and database user needed by the example programs shown in Chapter 12. This is the last major piece of technology you'll need to have installed to develop a full-fledged Java-based web application.

    Ensure you have MySQL set up properly and integrated with NetBeans. If you haven't already done the installation, follow the instructions found here for installing MySQL. When you've completed the installation, do the on-line NetBeans example tutorial which introduces you to using NetBeans together with MySQL to manage persistent data. Please make sure you note the "root" user password you set. You'll need it again later on.

    When you've completed this initial NetBeans/MySQL tutorial, please take a screenshot of your NetBeans window making sure that the data from one of the tutorial tables is visible on the screen to show that you were successful in setting up everything. Upload this screenshot in a file to the class FTP server as part of this week's assignment.

    [ FYI: you typically take screenshots in Windows using the "PrtSc" or "Alt-PrtSc" (PrintScreen key) to capture a bitmap of the screen which is placed onto the Windows clipboard where you can then paste it as an image into a document file in order to save it permanently; here's a general explanation of how the PrtSc key works in Windows to do this. ]

  5. Start the database and table creation by printing out the log file of a previous session called create-webhomecoverdb.log. You'll use this a guide for what comes next. Also, you should download the SQL script file, 'webhomecoverdb.ddl', into some well-known directory such as "\tmp", since we'll be requiring it later on and need to easily locate it.

    Then start the "MySQL Command-line Client" tool available on your computer (it was installed when you installed MySQL and is accessible from the main Windows Start menu under the MySQL programs folder or it can be run directly inside a Windows Console window as "mysql"). In either case you'll be logging into the tool as the "root" user using the same root user password you chose during the MySQL installation process.

    This mysql Command-line Client is the same tool shown on page 9 in the SQL Refresher PDF file. Before you start doing anything else with it after starting it up and logging in as root, use the mysql tee command (type '?' within mysql to see a list of all it's built-in commands) to save all your interactions to an output file. This log file should also be uploaded to the FTP server to demonstrate this part of your assignment this week.

  6. Next refer to the "create-webhomecoverdb.log" file and and repeat the sequence of commands shown in there to create a new database called webhomecoverdb in your own local MySQL instance. This is the database that will hold all the data from our Parsons' textbook examples. The program's command-prompt is shown in the log file as: "mysql>". What follows this prompt is the command (each is terminated with a semicolon) that you must type in order to get the result that follows it in the create-webhomecoverdb.log file.
  7. Using that create-webhomecoverdb.log file as a model, replicate each of the commands you find there. You'll start by creating a new 'webhomecoverdb' database. As part of the table-creation process you'll be executing the 'webhomecoverdb.ddl' SQL script file you downloaded previously using the source command to load the table definitions and data from it into the webhomecoverdb database.
  8. Once the webhomecoverdb database is completely set up, then you can do Exercise 12.1 in Parsons on page 466.
  9. Besides those three SELECT statements mentioned in 12.1, please also show at least two examples of each of the following SQL commands: INSERT, UPDATE, and DELETE, using different combinations of columns and WHERE clauses from the three tables. After each of these commands do a 'SELECT * from XXX' where 'XXX' is the name of the table you just operated on to show the changes to the data in the table.

    When you're all done with this part of the assignment, quit the mysql tool and upload your saved log file to the class FTP server.

8 03/05/10 TBD
9 03/12/10 TBD
10 03/19/10 TBD