Lab 2. DB and Taglib
CS320, Spring 2005


Please upload your files using the online turnin server. The files should include all the source code, documentation, and an HTML file lab2.html, which contains a link to your JSP page on the CS server. Note that file uploading will be disabled automatically after 7:40PM, so please turn in your work on time.


[Q&A] (4pt)  Suppose we want to implement a custom tag <foobar> using a Java class Foobar.java. The tag will be used as <cs320:foobar foo="a" bar="b"/>, or in other words, with two attributes but no body content. We also assume that the home directory of your account on the CS server is $HOME. Please write down your answers to the following questions on a piece of paper, and show it to the instructor before you proceed to the next section.

1. Which Java package(s) should you import in Foobar.java?

2. Which class should Foobar inherit from? and which method(s) should be overridden in Foobar?

3. What method(s) do you need to implement in class Foobar in order to support the two attributes foo and bar? Write down only the method header(s).

4. In order to compile Foobar.java, which class library should be included in the classpath? and where is this class library on the CS server?

5. Under which directory do you put the compiled Foobar class?

6. Under which directory do you put the TLD file for the custom tag?

7. The uri attribute in a TLD file is
A. The URL to the location where the tag library can be downloaded.
B. The URL to the location where the TLD file can be downloaded.
C. A unique identifier for the tag library, and it can be any string, e.g. not necessarily URL-like.
D. A unique identifier for a tag in the tag library, and it can be any string, e.g. not necessarily URL-like.
8. An attribute element in a TLD file has five possible attributes: name, required, rtexprvalue, type, and description. All these attributes are fairly self-explanatory except rtexprvalue, which could be either true or false. What does this attribute do?

[Programming]  In this lab we'll create a voting page for American Idol.

[SQL] (2pt) Create the following two tables, Contestants and VotingPeriods, in your database, using proper attribute type for each attribute:
Contestants:
Name Votes
Anthony -1
Bo 0
Carrie 0
Vonzell -1
VotingPeriods:
Start End
2005-5-11 21:00 2005-5-11 23:59
2005-5-18 21:00 2005-5-18 23:59
2005-5-26 19:00 2005-5-26 23:59
Note that an initial Votes of -1 indicates that the contestant has been voted off, and we assume that there is no overlap between voting periods. For this problem, turn in a file idol.sql which includes the SQL statements to create and populate the tables.

[JSTL SQL] (4pt) Create a JSP page Vote.jsp which performs the following operations:
The voting period hasn't started yet.
The voting period has ended.
Bo
Carrie
[Taglib] (extra credit +4pt) Create a custom tag <showVotes> which can be used to display the current number of votes received by a contestant. For example, <idol:showVotes name="Carrie"/> should display the number of votes Carrie received.