COMP S380F Take-home Assignment 22 May 2022 (Sun) 10:00 – 25 May 2022 (Wed) 10:00
Instructions:
COMP S380F Web Applications: Design and Development Take-home Assignment
22 May 2022 (Sun) 10:00 – 25 May 2022 (Wed) 10:00
Copyright By PowCoder代写 加微信 powcoder
This paper contains SIX questions. Please answer ALL of them.
• For the written questions, you are required to hand-write your answers clearly and convert them into a single PDF file for submission. Computer-typed answers are not accepted.
You have to work on blank papers, take photos on them, and use the app “Adobe Scan” to convert your photos into a PDF file: https://acrobat.adobe.com/hk/zh-Hant/mobile/scanner-app.html
If you can write on your screen and convert your work to a PDF file, it is also acceptable.
• For the programming questions, you are required to code two maven web application projects and zip them for submission.
(Please clean your Maven web application projects in NetBeans to remove all the compiled files and zip the two web applications in a single zip file)
Please submit your PDF and ZIP answers to both the OLE and Keith’s email address with the email title “[COMPS380F] Take-home assignment answers” (for backup purposes).
Note that copying from others or the Internet will lead to a zero score. Note also that OLE accepts only one submission. Please make sure your work is correct and does not miss any pages or files before you submit your answer. If you have any problems, you can send Keith an email.
COMP S380F Take-home Assignment 22 May 2022 (Sun) 10:00 – 25 May 2022 (Wed) 10:00
Part I (70%)
The following questions concern the given Maven web application project “Exam1”.
This web application allows users to play a number guessing game. The game can be played by accessing a gameServlet with URL pattern /guess and /play. In each game, an answer, which is an integer from 1 to 50, is randomly generated. A user can guess the answer with multiple trials.
The following shows the output for different scenarios.
(1) If the user hasn’t played any game yet:
(3) If the user’s guess (e.g., 50) is larger than the answer:
(2) If the user’s guess (e.g., 25) is larger than the answer:
The game ID (gameNum), the number of trials in the current game (trial), and the randomly generated answer of the current game (ans) are stored as session attributes.
(4) If the user’s guess (e.g., 43) is the same as the answer:
COMP S380F Take-home Assignment 22 May 2022 (Sun) 10:00 – 25 May 2022 (Wed) 10:00
Question 1 (20 marks)
(a) If a user makes a guess attempt, the number of trials will increase by 1. In the doPost() method of gameServlet, it is implemented by the following code snippet:
Integer trial = (Integer) session.getAttribute(“trial”); trial += 1;
Yet the number of trials fails to increase. Explain the problem and correct the code in the web
application. Please indicate clearly what code change you have made. [4 marks]
(b) Suppose the web application is deployed at http://www.exam.org/Exam/. Two users, each using a single web browser, access the web application with different actions. The following table
shows the web container events at each time, including
• NewThread: This event indicates that a new thread is created in the web container.
• NewSession: This indicates a new session object is created in the web container.
• NewServlet: This indicates that a new instance of gameServlet is created.
• doGet: This indicates the doGet() method of gameServlet is executed.
• doPost: This indicates the doPost() method of gameServlet is executed.
• destroy: This indicates the destroy() method of gameServlet is executed.
Complete all the table rows. [16 marks]
Time Action
1 The web application is deployed at http://www.exam.org/Exam/.
2 User 1 accesses http://www.exam.org/Exam/guess.
3 User 1 makes a guess and presses the Submit button.
4 User 2 accesses http://www.exam.org/Exam/play.
5 User 2 makes a guess and presses the Submit button.
6 User 1 presses the hyperlink “Start a new game”.
7 User 2 accesses http://www.exam.org/Exam/guess.
8 The web application is undeployed.
9 The server of http://www.exam.org is shut down.
Web container events
COMP S380F Take-home Assignment 22 May 2022 (Sun) 10:00 – 25 May 2022 (Wed) 10:00
Question 2 (25 marks)
A new function to keep track of the game history of each user will be added.
(a) Decide whether the game history (an ArrayList
attribute, session attribute, or context attribute. Justify your choice. [5 marks]
(b) For the new function, add a new Servlet HistoryServlet.java with the URL pattern /history and a JSP page history.jsp to display the guess attempts, as shown below. You
also need to modify the Servlet GameServlet.java. [20 marks]
If the user hasn’t played any game yet: If the user has played some game(s):
Question 3 (15 marks)
Add a single filter GuessFilter.java which filters requests to the URL patterns /guess and /play. It checks the user’s guess (a request parameter guess). If it is not an integer in 1 to 50 (i.e., it is an integer out of range or not an integer), the user will be redirected to input again in the corresponding HTML form (with the same URL pattern /guess or /play) and an extra query parameter error is added.
Hint: For URL redirect, you may use the getRequestURL method of the HTTPServletRequest object and the sendRedirect method of the HTTPServletResponse object.
Question 4 (10 marks)
(a) Identify whether MVC Model 1 or MVC Model 2 is used in the web application. Justify your answer. [6 marks]
(b) For this web application, discuss which one is the most suitable model out of MVC Model 1 and MVC Model 2. Justify your choice. [4 marks]
COMP S380F Take-home Assignment 22 May 2022 (Sun) 10:00 – 25 May 2022 (Wed) 10:00
Part II (30%)
This part concerns the web application “Exam2” to be completed by you in Questions 5 and 6.
Question 5 (15 marks)
Use the Spring MVC framework to rewrite the given web application “Exam1” in Part I to a new web application “Exam2”. All functions and their URL patterns should be the same as that in “Exam1” (excluding the destroy() method of GameServlet.java, the game history by HistoryServlet.java, and the guess checking by GuessFilter.java).
Question 6 (15 marks)
We will store all games performed by all users in a relational database. Note that different users can be identified by different session IDs.
(a) Decide whether you will use Java JDBC or an Object-Relational Mapping (ORM) tool to persist
the data. Justify your choice. [5 marks]
(b) Use Spring Data JPA to persist the data of all user operations into the following table in an
Apache Derby database:
• Table name: history
• Table columns (name, data type: meaning):
➢ id, INTEGER: Primary key that is auto-generated by the Derby database ➢ gameUser, VARCHAR(50): Session ID of the user’s session
➢ gameNum, INTEGER: game ID
➢ trials, INTEGER: the number of guess attempts in the game
➢ status, VARCHAR(50): “Success” or “Fail” (the game is given up)
Include the database name, username, and password for your Apache Derby database, and the
SQL file in your web application zip file. [10 marks]
[End of Take-home Assignment]
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com