Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. (80pt) Create a Dynamic Web Project in Eclipse, then create a servlet called Addition Practice as follows. The Addition Practice servlet should behave like

image text in transcribed

1. (80pt) Create a Dynamic Web Project in Eclipse, then create a servlet called Addition Practice as follows. The Addition Practice servlet should behave like what's shown in this video. In doGet(), generate two random numbers between 1 and 9, and display a form that asks the user to enter the sum of the two numbers. For example, suppose the two random numbers are 6 and 2, the form should look like the following: 6+2 = 8 Check Answer In doposto, display the correct answer, the user's answer, and tell the user if their answer is correct. For example, suppose the user entered the answer 9 (we assume user always enter an integer), the display should be: 6+2 = 8 Your answer 9 is incorrect. Try Again Clicking on Try Again should take the user back to the form with two new numbers. HINT: Use the nextInt(int bound) method in Random to generate the random numbers. Since the form submission is handled by the dopost() method of the same servlet, the action attribute of the form generated by doGet() should be the URL to the servlet, and the method attribute should be "post". NOTE: You do NOT need to create HTML files for the web application. 2. (10pt) The difficult part of the previous exercise is how to get the two random numbers in dopost() in order to check the user's answer and display the result. There are several ways to do it: Store the two numbers in two variable of the servlet class. Store the two numbers in the application scope. Embed the two numbers in the form generated by doget() using two hidden form fields, so they will be submitted to doPost together with the user's answer. Briefly discuss why the last approach is better than the first two. Please put your answer in lab9.html. 1. (80pt) Create a Dynamic Web Project in Eclipse, then create a servlet called Addition Practice as follows. The Addition Practice servlet should behave like what's shown in this video. In doGet(), generate two random numbers between 1 and 9, and display a form that asks the user to enter the sum of the two numbers. For example, suppose the two random numbers are 6 and 2, the form should look like the following: 6+2 = 8 Check Answer In doposto, display the correct answer, the user's answer, and tell the user if their answer is correct. For example, suppose the user entered the answer 9 (we assume user always enter an integer), the display should be: 6+2 = 8 Your answer 9 is incorrect. Try Again Clicking on Try Again should take the user back to the form with two new numbers. HINT: Use the nextInt(int bound) method in Random to generate the random numbers. Since the form submission is handled by the dopost() method of the same servlet, the action attribute of the form generated by doGet() should be the URL to the servlet, and the method attribute should be "post". NOTE: You do NOT need to create HTML files for the web application. 2. (10pt) The difficult part of the previous exercise is how to get the two random numbers in dopost() in order to check the user's answer and display the result. There are several ways to do it: Store the two numbers in two variable of the servlet class. Store the two numbers in the application scope. Embed the two numbers in the form generated by doget() using two hidden form fields, so they will be submitted to doPost together with the user's answer. Briefly discuss why the last approach is better than the first two. Please put your answer in lab9.html

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions