1. Hopefully you already have tomcat working on your home
system; if not, use the directions in Home
a. Set up the $cs636/servlet1 project as a Dynamic Web Project in eclipse, if you haven't already. Be sure the unzipped project is in a directory not in the tomcat area. In eclipse oxygen, you can use Open Projects from File system> Directory...and see that the new project is a Dynamic Web Project. Specifically you should see a little blue world icon sitting on the project icon in Package Explorer, and project Properties should show the Project Facet "Dynamic Web Module" checked. Report on success or any problems. Deploy the servlet1 project to tomcat. You can use "ant deploy-xxxdb" from the command line (or inside eclipse in an ant view), or if you followed the directions in step 5 of Home tomcat setup to set up tomcat inside eclipse, use the Servers view to get eclipse to deploy it by right-clicking the tomcat icon in the Servers view and then "Add and Remove..." to add the project. The advantage of the last approach is that eclipse will automatically update the deployment when you make an edit to the servlet sources, so you don't have to "ant deploy-xxxdb" over and over. Report on how you deployed the project, and success or failure with "ant test1" or "ant test1c".
b. Break the servlet code by commenting out the call that gives
a good value and instead make
out = null:
// PrintWriter out = response.getWriter();
PrintWriter out = null;
Redeploy the servlet with "ant deploy" at the command line or let eclipse do it for you automically if you added the project via "Add and Remove". Either way, check your webapps directory for a recently written servlet1 directory using "dir" (Windows) or "ls -l" (Mac/Linux). Show the output of this command in your paper. After 1 minute, run the servlet using "ant test1" or "ant test1c", and report the (failing) response.
c. "Debugging" this error. Get the browser to handle this error by browsing to the URL used in test1. Note how the browser displays the returned HTML even on a HTTP 500 error (unlike wget) and this is useful because tomcat catches the exception and sends debugging information in this response HTML, specifically, the stack trace of the failure. Give the URL you used in your browser to cause the error, and copy the lines from the response shown in the browser into your homework paper that show where the problem is in the servlet source. Note that these lines also show up in tomcat's logs (not the main one), but they are not so easy to find.
d. Optionally, if you have tomcat working inside of eclipse, set a breakpoint in doGet. Run tomcat in debug mode from
eclipse and see it hit the breakpoint. Report on what you see on the
execution stack. You now are ready to debug development servlet code.
2. Transfer the provided $cs636/ch07download project to your development system and start up a Dynamic Web project for it. Note that this project does a part of project 2, but does not take advantage of our track table data.
a. Deploy this project to tomcat running in eclipse or outside eclipse and use a browser to play a sample song for a CD, noting any problems.
b. Note that this project comes with a build.xml. On the command line or eclipse ant view on your development system, try ant clean, ant build, ant deploy, ant test1, and ant test1c if you have curl on your system. Note any problems. Explain what these tests are doing.
c. Explain why this project qualifies as MVC.
3. Transfer $cs636/pizza3 to your development machine and unzip it up in a convenient directory outside tomcat's area. Unlike servlet1 and ch07download, this project accesses database tables via a DataSource connection pool set up by tomcat. See handout about needed configuration of tomcat's conf/context.xml to configure the DataSource for each database. Report on any problems. Bring down tomcat and eclipse while you first set up tomcat's context.xml, then bring tomcat back up and get pizza3 working with ant before running eclipse again: ant deploy-xxxdb, ant webTest1, ant webTest2. (Eclipse, if running and configured for tomcat, will try to manage context.xml itself, which confuses the initial configuration.) Then bring up eclipse again and set up an eclipse project for pizza3. Note that pizza3 needs a Dynamic Web Project if you want tomcat working inside eclipse and get your edits to be reflected automatically in the deployed webapp. With eclipse oxygen, just use Open Projects from File System>Directory and see that the new project is a Dynamic Report on your success or problems in setting up the pizza3 project in eclipse, and note whether or not you configured tomcat within eclipse. If you don't configure tomcat within eclipse, remember to "ant deploy-xxxdb" after source edits that you want to test.
4. Analyze the differences between the pizza1 and pizza3 projects by using the powerful and convenient eclipse compare capability. In Project Explorer, select two packages, for example, one from pizza1and corresponding one from pizza3, and then right-click, choose Compare. Go through the diffs and report on each set of related edits, explaining why they are needed to change to a web app, or were used to separate the system into two part, sales and catalog. Don't include the diffs in your hw paper, just the discussion of them.
5. In pizza3, the room number of the student is the essential Session variable. Trace how the room number gets set in the StudentBean in one request cycle and later used in another request cycle. Specifically, follow Student Service link to the Student Welcome page, then set room 3, and see the page redisplayed with "room=3" in the URL query string. Then follow the "Order a Pizza Now" link to the Order Form page. There your choice of 3 shows on the Order Form page without being in an incoming query string. How does the code know to display 3 as your room number? It's because of the session variable, but can you be more specific? Give the name of the session variable, the method and line of code that sets the room in the session variable and the JSP's line of code that picks up the session variable value.