Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java Web Application that displays trivia about a number the user enters. Your application should consist of the following items: index.jsp Java Servlet

Create a Java Web Application that displays trivia about a number the user enters. Your application should consist of the following items:

  • index.jsp
  • Java Servlet
  • trivia.jsp

index.jsp

Your home page is where users will start the application. Your page should include an image and a description of what the application does. Include a form with a label, a textbox (for the user to enter the number), a hidden field, and a submit button. The hidden field should include the name of the action the user is performing "processNumber" would be a good choice, but you can decide what the name of the action should be. Make the page look nice - you may want use your CSS from Unit 3. Your form will need to call a servlet when the user clicks the Submit button.

Java Servlet

Your form should call your servlet with the post method. Your servlet should perform the following steps:

  • Parse the action from the request.
  • If the action is not "processNumber" (or whatever you decided), send the user to Index.jsp.
  • If the action is "processNumber":
    • Parse the number from the request.
    • Validate the number (should be an integer).
    • If the number is valid:
      • Call the Numbers API to get a trivia fact about the number (see below).
      • Add the trivia fact to the request.
      • Send the user to Trivia.jsp.
    • If the number is not valid:
      • Add an error message to the request.
      • Send the user back to Index.jsp.
      • Display an error message to the user.
      • Put the user's data back in the textbox.

trivia.jsp

Display the trivia fact about the number to the user. Use the same CSS you used on the Index.jsp page, and include the same image.

Also include a way for the user to return to the index.jsp page. You could do this with a Submit button as in the book's example. You could also do this with a hyperlink.

Numbers API

The Numbers API allows anyone to retrieve information about a number. Visit their website to learn more about it and the other features they provide. This is a simple example of calling an API to get information. We will do some more involved examples with other APIs in the coming weeks.

I have attached a sample Java console program that shows how to call the Numbers API. You may want to copy the callNumbersApi method into your servlet.

Tips

  • This week in class we went over a sample program that showed how to parse data from a request and validate it. That project is in Blackboard at the top of the unit. You may want to copy much of that code into your servlet to help you parse data and validate it. Do not copy the entire file though, as your servlet should have a more appropriate name for this assignment. You may also want to review that program to see how we connected the HTML form to the servlet.
  • You spent a lot of time creating a style sheet in Unit 3. Perhaps you want to use it as the basis of your style sheet for this assignment. I recommend getting your webpages to look the way you want them to now, as you can use your style sheet for the rest of the semester on all your assignments.
  • You do not need any JavaBeans (instantiable classes like the Contact class) for this assignment.

  • Have the image on the trivia.jsp page reflect the number the user entered (if it's 1-40). You can find images at KidsMathGamesOnline.com.
  • Give the user the option to enter a year. Do this by adding a second form on the index.jsp page that has a different action. Verify that the year entered is not in the future. The Calendar class can help you find the current year - don't hard-code it! See the Numbers API documentation on how to request information about a year.
  • Give the user the option to enter a date (month and day). Do this by adding another form to the index.jsp with yet a different action. Verify that the user entered a valid month / day combination. See the Numbers API documentation on how to request information about a date.

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

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

What is Centrifugation?

Answered: 1 week ago

Question

To find integral of ?a 2 - x 2

Answered: 1 week ago

Question

To find integral of e 3x sin4x

Answered: 1 week ago

Question

To find the integral of 3x/(x - 1)(x - 2)(x - 3)

Answered: 1 week ago

Question

What are Fatty acids?

Answered: 1 week ago