I've provided code for you for a new version of the Beer MVC Servlet from HFSJ, that uses Ant, JUnit, Javadoc and WAR files in a way that represents (as far as I understand them) "best practices" for doing Java web app development.
Ok, "best practice" is a bit of a buzzword. It is probably overstating the case to call what we are doing here "best practices". I'm sure that if we look into it more deeply, we'll find many ways we could improve our coding practices over what we are doing here.
Let's just say we are "upping our game" a bit from what we did on H06, and moving in the direction of how folks in the real world tell me that professional web app development is typically done.
Several things we are doing differently, all of which (I'm told) are considered by real-world Java developers to be good practice:
com.example
, which is a package name that should never be used in practice—only in textbooks!) public static void main
method that provides an alternative view/controller for our model (namely a command line interface). index.html
as the name of the first page of the user interface— instead of form.html
—so that you don't end up seeing the ugly "directory" screen containing form.html
and result.jsp.
Typing the name of the directory where the web app is located takes you right to the user interface. If you coasted through P05 by relying on other team members to do the Ant and JUnit work—well, now those chickens are coming home to roost. The Wiki pages for Ant and JUnit may help. You may also want to consult your fellow team members to help you if you are having trouble.
Also from now on, all Java code in this course should be commented with comments suitable for making documentation with Javadoc. There is a wiki page for JavaDoc also.
As you run into problems with Ant, JUnit, and Javadoc, and other technologies —and as you work through the answers to these problems—you are strongly encouraged to post the problems and solutions on the Wiki. Then, come see me, so that you can get choice point credit for your contributions!
This is Problem-Based Learning!
This is the style of learning you will need after you graduate.
In this assignment, you will:
The following reading is recommended:
You can obtain the source either as:
Download this to your development directory. You can do this directly on porsche as follows. This script shows getting both files, though in fact, you only need to get one or the other.
porsche[196] > cd porsche[197] > cd web-dev porsche[198] > pwd /usa/pconrad/web-dev porsche[199] > ls A08/ A08.new/ A08.zip beerAdvisor/ beerDBV1/ beerDBV1.src.tgz* beer.tar* porsche[200] > wget http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.tgz --21:49:02-- http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.tgz => `beerAdvisor.tgz' Resolving www.udel.edu... 128.175.13.63 Connecting to www.udel.edu|128.175.13.63|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 7,771 (7.6K) [text/plain] 100%[======================================================================================================================================================================>] 7,771 --.--K/s 21:49:02 (168.43 MB/s) - `beerAdvisor.tgz' saved [7771/7771] porsche[201] > wget http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.zip --21:49:06-- http://www.udel.edu/CIS/474/pconrad/07S/hwk/H07/beerAdvisor.zip => `beerAdvisor.zip' Resolving www.udel.edu... 128.175.13.63 Connecting to www.udel.edu|128.175.13.63|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 19,556 (19K) [application/zip] 100%[======================================================================================================================================================================>] 19,556 --.--K/s 21:49:06 (105.37 MB/s) - `beerAdvisor.zip' saved [19556/19556] porsche[202] > ls A08/ A08.new/ A08.zip beerAdvisor/ beerAdvisor.tgz beerAdvisor.zip beerDBV1/ beerDBV1.src.tgz* beer.tar* porsche[203] >
(Note that this will not work from the clients of porsche, since they are not directly connected to the Internet—so download on porsche, then ssh into your client to do the rest of the steps below.)
Note the build.xml file, and especially note the global.properties file. Note how we can take everything that would have to be change to move from one system to another, or one user to another, and we can factor it out into a file called global.properties.
Note that the package name is not com.example.*, but rather edu.udel.cisc474.pconrad.beerAdvisor.*
Note that every class and every method has Javadoc style comments.
Note that the model is tested with JUnit tests
Now, change the global.properties file so that instead of trying to deploy the javadocs and war files to pconrad's directories are porsche, the javadoc and war files are directed into your own directories on porsche.
Then, type ant, and notice the menu that comes up. Try all the various options in that menu.
The view consists of the files index.html
and result.jsp
in the web
directory.
Note that form.html
is now index.html.
Note the header comments in both index.html
and result.jsp
Note how both files contain proper XHTML that will validate. Note that we can validate the result of a JSP by doing a view source, and cutting and pasting the resulting X/HTML code into the box at Validate by Direct Input box http://validator.w3.org.
Note how this version of the JSP uses the for each construct of Java 5.0.
Note that the controller also has Javadoc comments.
If you modified the global.properties file correctly, you should be able to go to your own tomcat, and type in http://porsche.cis.udel.edu:xxxxx/beerAdvisor and see the servlet come up.
Try modifying something in the view, in the Model and in the Controller, and type ant deploy-war
Make sure that everything is working properly, and that you understand all the magic that is taking place!
The purpose is get comfortable with all of these "best practices", so that you can use them in your group project, and in your choice projects (if you are using Java). If you are not using Java, you should still follow similar practices in PHP, or whatever technology you are using.
Now, create your own app, using the product you selected in H05. This will be an update of the product servlet you did in H06, but using all the "best practices" that you just reviewed in my "new improved beerAdvisor" code.
For each of the steps below, refer back to the equivalent part of Step 2 to be sure that you are "getting" the things you should be "getting" for that step. You may also want to look over the grading rubric at the bottom of this assignment.
You'll create a static HTML page http://copland.udel.edu/~jstudent/cisc474/H07 that contains
Here is some advice from the wiki on creating a tarball and creating a zip file
Be sure that the link you created in Step 4 works properly for downloading your source distribution.
Be sure when you go into WebCT, that you both upload and submit.
(The reason to have you also submit on WebCT as well as putting the code on the web is that submitting on WebCT (a) creates a permanent archive, (b) establishes a submission time, and (c) enables the TA to give you a grade.)
Item | Description | Points |
---|---|---|
Java code | Your Java code works and is well commented and structured | 20 |
Javadoc | Your code has proper javadoc (i.e. not the Javadoc that was in my code, still unmodified!) |
10 |
Ant | Your build.xml file looks reasonable | 10 |
JUnit | You have reasonable JUnit tests | 15 |
WAR file | You used a WAR file | 10 |
Scripting and Submitted | You followed instructions for scripting and submitting | 10 |
Reasonable package names | No example.com type package names | 5 |
index.html | Not form.html | 5 |
tarball or zip file of source distribution works properly |
Top level directory is correct, you can unpack and do Ant, and get a menu. global.properties need to be changed only for classpath, and for deployment reasons. | 5 |
HTML validates as HTML 4.0.1 strict, XHTML 1.0 strict, or XHTML 1.1 | You should have a validation icon on your index.html, and your "result" HTML should validate when you copy and paste the view source of the resulting HTML (not the JSP source) into the "validate by direct input" box at http://validator.w3.org (the third one down). | 10 |
TOTAL POINTS |