CS 143

Project 2

Partners

Please remember the ongoing rule about partnerships: If a student turns in any part of the project as part of a team, every later part of the project must be submitted individually or as part of the same team. Details of partnership rules can be found in the Project page.

Part A

In this portion of the project you will familiarize yourself with the Java Servlet technology and build a small Web interface that uses the Servlet, which replies back what you have typed in an HTML page.

You will use Java Servlets to implement the Web interface.

Detailed instructions for setting up the Apache Tomcat servlet container can be found in the Java Servlet at SEASnet page under the section "Setting up the Java Servlet server."

We are providing two sample files to demonstrate the basic functionality of Servlets, located at the /u/cs/class/cs143v/cs143vta/proj1/code/ directory.

Copy the files Copycat.html and Copycat.java to the appropriate directories in your own account. The Copycat.html file should be placed in the /usr/share/tomcat5/webapps/${USERNAME} directory from Step 1, and the Copycat.java should be placed in the /usr/share/tomcat5/webapps/${USERNAME}/WEB-INF/classes directory.

First you must compile your .java file. To compile the Copycat.java source code, you can run the following command:

javac -classpath "/usr/share/tomcat5/webapps/cs143ta/servlet.jar" Copycat.java

This command will compile Copycat.java (Java source code) into Copycat.class (Java "class" or "object" code).

Don't forget to modify your web.xml to reflect the presence of the new Copycat.class servlet. Mimic the example provided by Hello.class servlet

Once you had compiled Copycat, and modified web.xml you can test your servlet by going to:
http://lnxsrv03.seas.ucla.edu:8143/${USERNAME}/Copycat.html

Read the Copycat.html and Copycat.java files that are provided. Make sure you understand how they work. For detailed documentation you may want to refer to the Java Servlet Technology from Sun.

In this step, you will write a Web interface that allows the user to select an input and submit a form, which results in an output page (served by your servlet) that displays the selected input. Your Web interface should contain a drop down box allowing the user to select one of 5 options (namely Option 1, Option 2, Option 3, Option 4, and Option 5 – Option 1 selected by default), and the servlet will then generate the appropriate .html page with the user input as part of the output. Copycat.java and Copycat.html should give you a good starting point. In order to finish the project, you will only add around five lines of code to Copycat.java and change about 5-10 lines in Copycat.html. Please document your own additional code to improve legibility.

Name the html file P2A.html where the user will select an option, and the java file P2A.java that will generate the appropriate .html page.

Part B: JDBC

In this portion of the project, you will connect the Web interface you have build in P2A and the MySQL Database using JDBC (Java Database Connectivity) API (application programming interface). JDBC allows an application or an applet to establish a connection with a database or access any tabular data source, send SQL statements, and process the results. Dataset and the tables from project 1 are used here.

queryResults = stmt.executeQuery(String query);

where stmt is of type statement which is used to send your SQL statements to the DBMS. The queryResults variable is of type ResultSet, and can be manipulated in the while loop of the doGet method. Executing any valid SQL query is simply a matter of passing a different query string to the executeQuery method. Read more sample files available in JDBC at SEASnet to learn more aspects of JDBC.

Part C

In this project you are to create a fully functioning Movie Database system accessed by users exclusively through a Web interface. You may use your Web-database code for Project2-PartB as a starting point for this project, or you may start from scratch. The functionality of your Movie Database system is quite flexible, although we expect all students to implement some baseline capabilities:

For input pages:

Note that when your servlet program gets an input from the user, your program has to lookup either the MaxPersonID or the MaxMovieID table, assign a unique ID to the new actor/movie, and increase the MaxPersonID or MaxMovieID.

For browsing pages:

For search pages:

 

As a result, you would have created 3 input pages, 2 browsing pages and one search page.

Notes:

Your Web interface front-end and connection to MySQL should include at least the following features:

As you start modifying data in a database, you will undoubtedly want the ability to get a "fresh start" easily from your original data.

We recommend that you establish a routine of saving all data in MySQL load files, and perhaps reloading the database each time you start working with it. Remember to delete the contents of each table (or destroy and recreate the tables) before reloading. Otherwise, unless you take APPEND out of your control file (or there is a declared key), MySQL will happily append the new data to your old table, causing your table size to double, triple, quadruple, etc. To get rid of a table called T, issue the following command to MySQL:

DROP TABLE T;

If you want to get rid of all tuples in T without deleting the table itself, issue the command:

DELETE FROM T;

Hints:

There are many ways to design good web interface programs. Feel free to skip these hints if you want to make your own design. These hints are provided only as additional help for those who need them, but you are under no obligation to follow them.

Hints on general design:

In this project, you will have multiple operations with different SQL commands. You can probably do so by writing one servlet per operation, and designing web forms to call the appropriate servlet for each operation. However, it is easier (and more expandable) to write only one servlet to take care of all operations. The servlet should expect a parameter operationID that dictates which operation to carry out. For example,

OperationID

operation

1

display table Movies

2

display table Actors with name = 'X'

3

insert one tuple into table Actors

Your servlet will read the parameter operationID and decide which functions to call, and what other parameters to read (if any).

The parameter operationID can be conveniently passed from a web form to the servlet through the use of "hidden" input:
<INPUT TYPE="hidden" NAME="operationID" VALUE="1">

In addition, you might want to set up a "main menu" page with links to web pages that handle different operations. This can be done with HTML and no programming.

Hints on link-based browsing:

Note that your servlet can be called directly through a URL in the following way:
http://lnxsrv03.seas.ucla.edu:8143/servlet/myServlet?param1=value1&param2=value2&param3=value3
where myServlet is the name of your servlet, and the string after the question mark contains parameters passed to the servlet just like in a "GET" method. So you can implement link-based browsing by generating result pages containing hyperlinks of the above format, with appropriate parameters that instruct your servlet to execute the right query.

 

In adding user reviews to a movie, you may need to obtain the current timestamp.

While the functionality of your Movie Database system is quite open-ended, the interface itself is extremely open-ended. This class is not a user interface class and you can certainly get full credit for a solid system with simple input boxes, menus, and/or radio buttons, and simple HTML output tables. However, we welcome much snazzier interfaces, with the something resembling IMDb.com itself, or perhaps even something better!

What to submit (due Monday, November 16th, 4pm)

You need to submit electronic copies by noon and the paper copies in class at 4pm.

Note: Don't forget to login to ugrad.seas.ucla.edu using your CS143 LOGIN and issuing a submit command as you have done for Project 1

Follow the following order for submitting the paper copies: 1) README, source code of the html files, then java files, then screen shots.

Paper copies are due in class. Use the submit command as you did in project 1 for electronic submission. Filenames are not fixed in Project 2, since each team may have different set of files. Please give reasonable names to your files.