Lab 2. DB and Taglib
CS320, Fall 2004


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 links to your JSP pages on the CS server. Note that file uploading will be disabled automatically after 3:10PM, 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 HTML we may change the color of some text by using the <font> tag with the color attribute set to some color code. For example, <font color="#ff0000">This is some red text.</font> produces the following line of text:
This is some red text.
In this lab, we will create some JSP pages that display text in different colors according to the time of day when the page is requested. For example, if the page is requested between 4pm and 8pm, display the text in red fonts; if it's requested between 8am and noon, display the text in green fonts; and so forth.

[SQL] (2pt) Create the following table in your database, using proper attribute type for each attribute:

color
code
start_time
end_time
green
#00ff00
8:00
12:00
blue
#0000ff
12:00
16:00
red
#ff0000
16:00
20:00

For this problem, turn in a file mapping.sql which includes the CREATE TABLE statement as well as the INSERT statements which insert the three tuples.

[JSTL SQL] (4pt) Create a JSP page JSTLColor.jsp which displays some text, and the color of the text is determined by the time when the page is requested and the time-color mapping defined in the database table. In particular, use the SQL tags in JSTL to query the database for the proper color to use, and if the query result is empty, e.g. the page is requested before 8am or after 8pm, use color black (#000000) by default.

[Taglib] (extra credit +4pt) Create a JSP page TaglibColor.jsp with the same requirements as before, except that instead of using JSTL SQL library, use a custom tag, for example.
<cs320:color>some text</cs320>
HINTS: