CS636 HW5:  MVC webapps,  session variables, pizza3's Spring controllers

Due Tues., May 4 by 11pm on Gradescope

1.  The Chap. 7 Cart app. Look at ch07cartS's cart.jsp. Suppose the user has 1 copy of pf01 and 1 of jr01 in the cart.
  1. Then the user updates the cart from 1 to 2 copies of pf01. What request (one line, ending with HTTP/1.1) goes back to the server? What form data (name-value pairs x=y) are in the request body?
  2. Then the user deletes the 2 copies of pf01. What request (one line, ending with HTTP/1.1) goes back to the server? What form data (name-value pairs x=y) are in the request body?
  3. How can the user add back the 2 copies of pf01? Give the 3 requests needed to do this: get another page, order 1 copy, get back this page again as response, do an update as in a.
  4. Explain why this project qualifies as MVC.
2.  The Chap. 7 Download app
  1. Download ch07downloadS.zip and unzip it on your home system, build it with "mvn package", and use "run” or "run.sh" to run it using embedded tomcat on port 9001. See its README for more information. Note that this project does a part of project 2, but does not take advantage of our track table data. Use a browser to play a sample song for a CD, noting any problems.
  2. After playing a sample, follow the link that lists session variables and note their names and values in your paper. For each one, find where in the code that session variable is set (session.setAttribute...), and where it is used. Briefly explain why these variables are session variables and not just request variables.
  3. Note that the method determineProductView operates differently for pf01 (forwarding to universal.jsp) and the rest of the CDs (forwarding to per-CD jsps, like pf02_download.jsp, as shown in the slides). Explain differences in user experience in the one case vs. the other three cases. Can you play all the samples for pf01 using this program? Do the song-playing pages look different?
  4. Improve universal.jsp to handle two songs for pf01 by setting attributes src1 and src2 and title1 and title2 for the two songs, and having two <audio> elements on universal.jsp. Show the new or changed lines of code for determineProductView and the new <body> of universal.jsp in your submission. Optionally, use Chrome's Inspect>Network to see any requests done by Chrome: you should see that Chrome does the three-CD-case GET to the mp3 but not the pf01 case, because it's done by tomcat itself, so Chrome doesn't know about it.
  5. Note that the src in the <audio> element provides the URL back to to the servlet of form "/download?params". In particular, what is the action parameter value?  What method of DownloadServlet is executed because of this action value? Note that you can ignore the lines of code (lines 204-209) trying to identify the RequestDispatcher (they don't do anything, I should have deleted them). This code shows how to gain control when the user actually downloads the sample, so you can record the download for the exact track they downloaded. You can add the trackid to the params for more direct id of the track (in the project, not this homework.)
3.   Pizza1 vs Pizza3. 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 pizza1 and the corresponding one from pizza3, and then right-click, choose Compare. Go through the diffs and report on each set of related edits (to files that exist in both versions), classifying them as needed to change to a web app, or to add transactions, or to use Spring beans, or to use a Spring-instantiated DataSource.  Don't include the diffs in your homework paper, just the discussion of them.

4.  The room number session variable in pizza3. In pizza3, the room number of the student is the essential Session variable. Investigate how the room number gets set in the StudentBean in one request cycle and later used in another request cycle. Specifically, follow the "Student Service" link on the welcome page 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 room 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 order form's JSP's line of code that picks up the room number (for the order form display) from the session variable.

5. Pizza3's Spring Controllers.

  1. Note that browsing to localhost:9002 or localhost:9002/index.html fail for pizza3 (but localhost:9002/welcome.html should work). Make pizza3 show the student welcome page in these cases by adding @RequestMappings to the StudentController following the form of the existent @RequestMapping for "welcome.html". Show your added code in your paper.
  2. Read pizza3's AdminController to see still another way to run SystemTest, and try it out. Record the URL you used. Note that this is using initializeDB.jsp, which makes it sound as if it is doing an initialize-DB action. What does this JSP actually do? Admittedly this is not great naming.
  3. In most cases the controller handler method returns a string that specifies a JSP to forward to. But a few cases return "forward:something.html". These are forwarding to the handler for endpoint something.html (servlet-to-servlet forwarding). Find these cases and describe what is happening in the UI at these times. There is also one case of a "redirect:something.html": this causes a redirect action. Discuss this as well if you know how redirects work, else treat it as if it said forward:, since that also works to pass control to the indicated handler. See Wikipedia page on Post/Redirect/Get if interested. Redirects are also used to transfer control to a URL outside the current servlet context: this use is described in our text on pg. 144.