Lab 2. DB and Taglib
CS320, Spring 2006



[Q&A] (4pt)  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 Programming section.

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, i.e. not necessarily URL-like.
D. A unique identifier for a tag in the tag library, and it can be any string, i.e. 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] Please upload your files using CSNS. 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 open until midnight, but there will be a penalty of 2pt for work submitted after 7:50PM.

Company X is conducting a promotion, which works as follows:

In this exercise, you are going to help Company X to implement the promotion website.

[SQL] (2pt) Create the following two tables, Rewards and Customers, in your database, using proper attribute type for each attribute:

Rewards:
Code Reward ClaimedBy
2576 a TV
john@hotmail.com
2886 null null
2567 an iPod
null
2625 null null
Customers:
Email Name
john@hotmail.com John

Note that the Rewards table contains a list of codes and the rewards associated with them. The Reward field could be null, which means there is no reward. The Customers table contains a list of customers and their email addresses. Note that an email address uniquely identifies a customer, or in other words, you should not have two rows in the Customers table that have the same email address.

For this problem, turn in a file lab2.sql which includes the SQL statements to create and populate the tables.

[JSP] (4pt) Create a JSP page GetReward.jsp. When GetReward.jsp is requested without any parameter, it displays the the following form:

Code:
Name:
Email:

Once a customer fills out the form and clicks the Get Reward! button, the application checks the user input and the content of the database, updates the database if necessary, and displays one of the following messages:

For this problem you may use either Java beans or JSTL SQL tags to access the database. Using JSTL SQL is likely to be easier.

[Taglib] (extra credit +5pt) Create a custom tag <info> with one attribute rewards, which can be used to display some information about the rewards. In particular:

Create a JSP page to show that the tag works correctly.