The following homework assignment should be completed after P02, your resin installation.
In the textbook (Head First Servlets and JSP), first:
Before you start, modify your "path" (the one that tells unix where to look for executables) so that $JAVA_HOME/bin is early enough in your path so that when you type in:
> which javac
the output is
/usr/local/j2sdk1.4.0_01/bin/javac
If you don't know how to do this, consult a Unix textbook, or a Unix guru. It has to do with editing your .cshrc and/or .login (or on bash, your .profile, etc. etc.)
Your book walks you through creating a small web applications using the MVC design pattern. The explanations in the book are very thorough, so we will not recreate them here. We are just going to point out the things that you need to do differently since the book is based on Jakarta Tomcat/Apache, and we are using Caucho Resin instead.
$RESIN_HOME/bin/httpd.sh start
404 Not Found /Beer-v1/SelectBeer.do was not found on this server. Resin 2.1.16 (built Tue Feb 15 11:12:27 PST 2005)Seeing this error message now will help you understand what the purpose of the next steps are, where you are implementing the thing that makes "SelectBeer.do" work properly.
Well, yes and no. It is true that for now, we aren't too worried about what all that stuff means. But we do have to modify it a bit to make it work with Resin."You don't have to know what any of this means, just type it in".
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
Here's what you are going to need instead (a proper subset of the text above):
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
For the intellectually curious for whom "Don't worry about it; just type it
in" is too torturous, here's the quick
explanation: the attributes of the web-app tag that we are leaving out are attributes
that specify the XML schema for the deployment descriptor. These must be specified
in the web-app element for Tomcat, but they are
built
in
to Resin
as defaults.
Important:One more step is needed beyond what you have in the book to make this work with Resin. In your resin.conf file, add the following lines somewhere in the section that lists <web-app> tags:
<web-app id='Beer-v1/'/>As we all gain more familiarity with Resin and its configuration, perhaps we'll find a way to make it work without this. For now, this seems to be necessary.
Continue with step 2 on page 77 exactly as shown, up through and including page 80.
A hint: On page 80, there is some code you have to type into a file. The book doesn't tell you the filename explicitly, but if you have a sound knowledge of the Java language, there is only one possible filename that would make sense. The roadmap on page 72 tells you which directory to put that file in.
javac -classpath $RESIN_HOME/lib/jsdk23.jar:classes:. -d classes src/com/example/web/BeerSelect.javaThere are similar compile commands on pages 85 and 90 that you'll need to modify in a similar fashion.
$RESIN_HOME/bin/httpd.sh restartDo this each time the book tells you to restart the server.
500 Servlet Exception java.lang.NullPointerException at _result__jsp._jspService(/Beer-v1/result.jsp:19) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135) at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:253) at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:170) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:536) Resin 2.1.16 (built Tue Feb 15 11:12:27 PST 2005)
That should take care of it! Once you have done all the steps in this chapter, we should be able to type in the following URL (replacing 8050 with your port number) and get the beer advisor application just like in the book:
http://jaguar.cis.udel.edu:8050/Beer-v1/form.html
Once your application seems to be working properly on your port number, you will now create a "clone" of this application for some other product (e.g. Coffee, Soft Drinks, Cars, Pizzas, etc.) Here's how:
Under ~/cisc474/web_dev (called MyProjects in the book), you currently have a directory structure rooted in a directory called beerV1. You will create a second directory structure called productV1. This directory structure should mirror that of beerV1,but will be written for some other product of your choice: it could be coffee, or cars, or bagels, or whatever, but should have a similar interface and similar functionality to the Beer Expert page.
To make sure that each student chooses a different product, register your choice of product on the discussion board labelled "Product for H02" in WebCT. First come first served. Be sure that your product is one for which you can come up with at least four distinct categories, and have at least two example instances of the product for each category.
Develop and deploy this application in the same manner as the beerV1 example application in Chapter 3. Call your development directory ~/cisc474/web_dev/prodV1, and use the exact same directory structure. The separation of development directory and deployment directory, and the specific directory layout given is a required part of the assignment, not an optional one.
We'll look under http://jaguar.cis.udel.edu:pppp/Prod-v1/form.html for your application (where pppp is your port number). So name it literally Prod-v1; don't rename it to Cars-v1 or Coffee-v1 or whatever.
// Instantiate a BeerExpert object, and iterate through all of // the beers that match the color selected by the user. For each // one, generate some HTML and write it to the output file.Add a reasonable number of such comments to the .java files for your clone application so that it is clear to your instructor and your TA that you know what the code is doing.
DO NOT just transcribe the "handwritten" comments in the textbook verbatim. Read those comments the first time you go through the code, but as you make the "clone" application, try to avoid reading them; instead, write comments in your own words based on your understanding of what the code is doing. (You can use those "handwritten" comments as a general guide for how much commenting is needed, and at what level of detail.)
In addition to these comments, be sure to have a comment at the top of each file similar to the following one that I wrote when testing out the assignment:
// BeerExpert.java // "Head First Servlets and JSP", 1st Edition, p. 82, O'Reilly (2004). // Transcribed by Phillip T. Conrad for CISC474, 02/25/2005 // // "Model" part of a beer advisory system based on the // Model-View-Controller design pattern.Note that this comment contains:
The same rules goes equally for you .java and for your .xml, .html and .jsp files; put similar comments at or near the top of all the files in your projects.
To do that, you'll need to figure out the correct syntax for comments in each of those types of files. (If you don't know it, that becomes one of your "Learning Issues" in the "Problem-Based Learning" sense of the word. Use the resources available to you---check the course web site for hints!)
Get your Beer-v1 and Prod-v1 applications up and running by noon on Tuesday March 8rd. By then you should also have a solution to the problem of restarting your server after jaguar is rebooted. If we find a server down, we'll check back one hour later (assuming that your script to check and restart the server should run at least once per hour.)