Skip to main content

Assignment #10

Trivia Servlet

Filenames: Trivia.html, Trivia.java

In this assignment, you will write a servlet that reads records from a server-based trivia text file, and displays selected trivia events on the user’s browser.

1. Create an HTML page that provides two radio buttons – the user can get trivia events for:

- the current date, or

- a specified month and day.

Use your HTML experience to provide a good user interface for this.

2. Write a servlet that will:

- retrieve the radio button option

- if the user selected "current date", get the current month and day

- if the user specified a month and day, retrieve those from the form

3. Getting the current date in Java.

You can use the GregorianCalendar class to get the current date and time. GregorianCalendar inherits some useful methods and constants from its direct superclass, Calendar. GregorianCalendar inherits a general-purpose accessor method named get, which receives a primitive int. It also inherits several constants that you can pass to specify what you want to “get”. To get the current day of the month, for instance, you can:

GregorianCalendar calendar=new GregorianCalendar();

int day=calendar.get(Calendar.DAY_OF_MONTH);

Make sure that you can get a numeric month and a numeric day for both options before you even think about reading the trivia file.

4. You can copy Trivia.fil into your classes directory:

cp /home/bis3523/resources/data/Trivia.fil .

Be sure to include the period at the end, which specifies the destination for the cp command.

5. Read the records from the trivia file, and display the events for the selected date. Generate good HTML.

6. In your index.html, change the href in the anchor tag for this assignment to Trivia.html.