Lab 2. DB and Taglib
CS320, Fall 2005



[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 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 1:20PM, so please turn in your work on time.

At the beginning of each CS320 class, I usually create a number of accounts on the CS server, and then assign the accounts to the students in the class. In this exercise, you are going to help me to automate this process.

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

Accounts:
Username Password CIN
cs320stu01 abcd null
cs320stu02 bcde null
cs320stu03 wxyz null
Students:
CIN Name
2001 John
2012
Joe
2008
Sue

Note that the Accounts table contains a list of accounts that can be assigned to the students, and the Students table contains a list of students who have enrolled in the class. Initially the CIN fields of the accounts are null, which means the accounts have not been assigned yet. Also for simplicity we'll assume that CIN is simply a 4-digit number.

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 GetAccount.jsp. When GetAccount.jsp is requested without any parameter, it displays the the following form:

CIN:

Once a user entered a CIN and clicked the Get Account button, the application performs the following operations:

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 students, which can be used to display some information about the students. In particular: