CS636 hw4 HTTP, JPA, Intro Servlets, tomcat

due Mon., Nov. 28, in class, on paper

  1. Learn about JPA and Object-relational Mapping. Read Chapter 13 of Murach, See JPA2 Notes for a guide to this chapter.

     a. Download and use ant to try out pizza2. See JPA2 Notes for details. Explain what "ant config-mysqldb" followed by "ant sysTest" does and how it uses ant to do it. Report on any problems. Note that "ant sysTest" expects a newly-loaded database, and database loads are handled in the database directory, as in music1-setup and pizza1.
    b. Set up the pizza2 project as a Java project in eclipse. Use eclipse to compare the domain packages of pizza1 and pizza2 and report on the differences, grouping similar differences. To compare two packages, select one in the Package Explorer, use control-click to select the other as well, right-click and Compare With>Each Other.
    c. Try out the supplied unit tests in at least 4 different ways, including ant commands and eclipse: select project in Package Explorer, right-click, Run As>JUnit Test. Give the ant commands you used.

  2. Try out tomcat, accessing just HTML pages to start.  Tomcat is the servlet-capable web server that we will be using to execute web applications.  I'll leave my installation of tomcat running on  topcat.cs.umb.edu (on port 11600) for your experimentation. Note that you need a tunnel from localhost:11600 to  topcat.cs.umb.edu:11600 to use this server, as you did earlier for the pizza page flow.  You can look at this tomcat's files at ~eoneil/cs636/tomcat-8.5 in the UNIX/Linux filesystem. My directory ~eoneil/cs636 only has the tomcat installation, made following the student instructions. In other words, I'm pretending to be a student in the class, but letting you see the results, whereas when you put subdirectories under your own cs636 directory, noone else in the class may see them. 
         First browse to http:// topcat.cs.umb.edu:11600  to see the "root" page. From home, use URL  http://localhost:11600/basicjsp/date.jsp, with a tunnel from localhost:11600 to  topcat.cs.umb.edu:11600.  You are using TCP port 11600, on which tomcat is listening on  topcat. You should see a picture of a tomcat and some text about the Apache Tomcat project.  Also links, including to some JSP examples of interest, but unfortunately written in old JSP. 
        Then browse to http:// topcat.cs.umb.edu:11600/cs636/index.html to see my little index.html page--you will be making a similar one for yourself.  This file index.html is situated at file path  ~eoneil/cs636/tomcat-8.5/webapps/cs636/index.html in the UNIX filesystem.  You are welcome to look at it there.   The webapps directory is the root directory of this website served by my tomcat. That's why the URL,  http:// topcat.cs.umb.edu:11600/cs636/index.html uses the part of the file path after webapps, the local path.  Report on what this page says. Follow its link and see another little page. The first page was served by tomcat. What server served the second page?
  3. Install Tomcat 8.5 on Linux system topcat.cs.umb.edu, following the instructions linked from the class web page.  As instructed there, make a little HTML page accessible at http:// topcat.cs.umb.edu:NNNNN/cs636/index.html, (via the tunnel) where NNNNN is the first port assigned to you, when your tomcat is running.  This installation for your own tomcat will be in your cs636 directory, protected from other student's access.  Don't worry, tomcat will be running under your user id, and will be able to read everything it needs.  IMPORTANT: Don't ever change permissions on your cs636 directory.  Report on success or problems.
  4. Tomcat and simple JSPs and servlets
    1. After you install tomcat on Linux, install the webapp named basicjsp from my Linux tomcat installation and use your ordinary browser to execute /basicjsp/date.jsp. From home, use URL  http://localhost:xxxxx/basicjsp/date.jsp, with a tunnel from localhost:xxxxx to  topcat.cs.umb.edu:xxxxx.
    2. Similarly install the basicjstl web app from my tomcat, with its count.jsp and guess.jsp.
    3. The servlet1 project: use "ant deploy" on your copy of this project to install in your tomcat.
    Run these and report on what you see, and what HTML is sent to your browser. This shows the minimal setup for JSP and JSP with JSTL. For JSP alone, all we have to have is an empty WEB-INF directory in the webapp. For JSP with JSTL (e.g. with <@ taglib... prefix="c"%> and <c: in use), all we have to do is put jstl.jar and standard.jar in WEB-INF/lib, as you see for /basicjstl.
  5. JSP execution and errors. Try the following on topcat, or your home tomcat if available.
    1. Try breaking count.jsp by removing the / from </c:forEach>. Report on the error.  Explain how it points to the bad line.
    2. Try breaking count.jsp by misspelling body in <body>, say by deleting the b.  What happens?  Make sure the edit was effective by viewing the page source in your browser.
    3. Find the generated java files for date.jsp and count.jsp under tomcat's work directory.  Report on their locations.
  6. Tomcat at Home: Report on success or problems for these steps
    1. Try out the installations in Home System tomcat installation described in steps 1-6.
    2. Download the servlet1 project and try “ant test1” to use curl or wget to do the HTTP GET to its URL. If you are using Windows and wget is unavailable, it means your executables path doesn’t include tomcat’s bin directory, where it resides (to fix this, see step 2 of Home PC tomcat installation). If you are using Linux or Mac, curl should be available on the system.
    3. Also redeploy servlet1 in your Linux tomcat (i.e. using "ant deploy") and try it out the two ways.  Report on your results.
  7. JSP and Servlets: second servlet example, EmailListServlet
    1. Unzip the provided ch05email.zip project and use “ant deploy” to deploy it in your home tomcat and try it out the two ways (browse to its known URL and use “ant test1”). If your home tomcat is not working yet, say so and continue.
    2. Also deploy ch05email in your cs.umb tomcat (i.e. using "ant deploy" on Linux at cs.umb.edu) and try it out the two ways, from topcat and also from users.cs.umb.edu.  Report on your results. Note that curl is available on users.cs.umb.edu and our other Linux systems at cs.umb.edu, as well as on topcat.
    3. Draw the page flow for this webapp as we did in class. If you wish, start by Xeroxing/scanning pg. 35 and then drawing on it, but drawing simple boxes is fine. It should show: 
      1. two boxes, one for index.jsp and one for thanks.jsp, the two pages.
      2. inside the boxes, show the form and the buttons
      3. an arrow from the submit button of the form to a big dot for the servlet, with an indication of parameters sent with this request. You could write “validation” next to the servlet dot.
      4. two arrows out from the servlet dot, one to each page, one marked “OK”
      5. an arrow from the button on thanks.jsp back to another servlet dot (the same servlet, but a different request), then on to index.jsp. Add info on any params here too.