COMP S380F Take Home Assignment (Project) Submission Deadline: May 12, 2020 23:59 1 In this take-home assignment project, you are required to submit two web applications and a PDF file containing your written answers. Please use CamScanner to convert your written answer to PDF and submit your work to the OLE. (Clean your Maven web application projects in NetBeans to remove all the compiled files and zip them as a zip file.) Part I (70%) The following questions concern the given Maven web application project “Exam1”. Question 1 (20 marks) (a) Consider the JSP pages add_form.jsp and multiply_form.jsp. Each of them tries but fails to display an initialization parameter (init parameter) named “class”, which is defined in the deployment descriptor web.xml. Explain the problem and correct code in the web application. [4 marks] (b) An init parameter can be stored in either a ServletContext or ServletConfig object. Describe one difference between these two objects, and identify whether the init parameter “class” is a context init parameter or servlet init parameter. [6 marks] (c) Suppose the web application is deployed at http://www.exam.org/Exam/. Two users access the following URLs at different times. The following table shows the servlet methods of the two Servlets AdditionServlet.java and MultiplicationServlet.java to be executed at each time. Complete the table rows using the format Servlet name.Method name, e.g., AdditionServlet.doGet. [10 marks] Time Event Executed methods 1 The web application is deployed at http://www.exam.org/Exam/. 2 User 1 accesses http://www.exam.org/Exam/add. 3 User 2 accesses http://www.exam.org/Exam/multiply. 4 User 1 presses the Submit button of the HTML form. 5 User 2 presses the Submit button of the HTML form. 6 User 2 accesses http://www.exam.org/Exam/plus. 7 User 1 accesses http://www.exam.org/Exam/times. 8 The web application is undeployed. 9 The server of http://www.exam.org is shut down. Question 2 (25 marks) A new function to keep track of a user’s history in performing additions and multiplications using the web application will be added. COMP S380F Take Home Assignment (Project) Submission Deadline: May 12, 2020 23:59 2 (a) Decide whether the user’s history (a Vector
object) should be kept as a request 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 history records, as follows: [20 marks] If no operations were performed by the user: If some operations were performed by the user: You also need to modify AdditionServlet.java and MultiplicationServlet.java. Question 3 (15 marks) Add a single filter NumberFilter.java which filters all requests of the web application and redirects the user to the corresponding HTML form page if: • The request parameters arg1 and arg2 exists, but one or both of them are not positive numbers (i.e., non-positive numbers or not numbers). Hint: You may need to call 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 (Project) Submission Deadline: May 12, 2020 23:59 3 Part II (30%) The following questions concern the web application project “Exam2” to be completed by you. Question 5 (15 marks) Use the Spring MVC framework to rewrite the 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”. Question 6 (15 marks) We will store all additions and multiplications performed by all users in a relational database. (a) Decide whether you will use Java JDBC or an Object-Relational Mapping (ORM) tools 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): ➢ id, INTEGER ➢ arg1, VARCHAR(50) ➢ arg2, VARCHAR(50) ➢ result, VARCHAR(50) • Primary key: id (auto-generated by the Derby database) Include the database name, username and password for your Apache Derby database, and the SQL file in your web application zip file. [10 marks] 欢迎咨询51作业君