Project 2: Starting Fabflix Business

Due: Apr 25, Friday, 11:45 pm. Submit on EEE under drop box / CS122B Project 2.


Project 2 Overview

In this project, you will start the Fabflix business! In particular, you will provide Web-based interfaces to allow customers to browse/search for movie information, add interesting movies to their shopping cart, and check out. The following figure shows the flow of the interfaces you need to implement.

The following are more details about the interfaces.

           

We are not specifying all the details of the interfaces. You are encouraged to use your imagination to enhance the functionalities. We highly recommend you implement the above using JSP and/or Java servlets at the server side. You can use any type of client-side technologies to enchance the functionality of your website (e.g Javascript, style sheets etc). Regardless of what client-side technology,  you will most likely make extensive use of HTML.


 

Installing and testing Apache Tomcat on Windows. Running a sample Servlet.

To support dynamic content on web pages and Java servlets (extensions of a server's basic services), we use Tomcat, a freeware package form the Apache Software Foundation. (You will be using its capabilities starting in Phase 2.) To install Tomcat

  1. Go to http://jakarta.apache.org/tomcat/; read a bit!

  2. Click on Tomcat 5.5 under Download (look on the left-hand side of the page).

  3. Select the 5.5.26 core binary distribution, the windows executable. (you can use the latest beta release at your own peril!); save the EXE file to your disk.

  4. Launch the EXE file you just downloaded.

  5. Click on Next; read the license and agree.

  6. On this screen select (check) Tomcat and Start Menu Items at minimum. Leave Documentation checked if you want the documentation on your drive (it is also available at the Tomcat site); check Examples if you want some examples of servlets. There are no files under WebApps. Click Next.

  7. Leave the destination folder as is; click Next.

  8. Leave the port at 8080--this is crucial. Choose an administrator login name and password: do not forget them! Click Next.

  9. Check that the directory listed is indeed where you have the java virtual machine (java.exe and its associated files) stored; if you used the default directories for java when installing it above, it is C:\Program Files\Java\jre1.6.0. Click Install.

  10. Wait a few minutes while installation occurs.

  11. Click Finish. Tomcat should start; the release notes file should be open in a window.

  12. Open your browser and open the page http://localhost:8080/ to see if TomCat is working.

Check over the release notes (and them close them). To be sure Tomcat is running, right click on the feather-like icon in the lower right of the Windows toolbar (if you hover over the correct icon, Apache Tomcat will appear); Start service should be grayed. To stop Tomcat at any time, right-click on the icon and select Stop service. You can also start and stop Tomcat on the General panel of the Configure Tomcat application (Start -> All Programs -> Apache Tomcat 5.5 -> Configure Tomcat).

To test that Tomcat is working and communicating with MySQL properly, we've prepared a servlet that performs basically the same tasks as the JDBC program; it queries the test database and returns some structural and content information. To run this program:

  1. Make sure the MySQL database server is running.

  2. Download TomcatTest.war

    A WAR file is a "Web Application Archive." It contains a compressed directory of the files needed for a ready-to-run java servlet that Tomcat will launch when you go to the Web page designated in the WAR. A WAR file must a have certain directory structure and contain appropriate files (with the appropriate contents) for Tomcat to launch the applet. If your TOMCAT installation was correct there should be a "webapps" folder under "Tomcat 5.5" directory of your Tomcat root installation (usually C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps ). You should place this .WAR here inside the webapps folder Check FAQs for questions regarding WAR. The default configuration of Tomcat should automatically "deflate" this .WAR file after a few seconds, so that you see a directory named TomcatTest under webapps. If not, you'll deflate it by following instructions under FAQs.

  3. We'll now "deploy" this application. Go to http://localhost:8080; this is your local web page. After installing Tomcat, it was set to the Tomcat welcome page; that page should appear.

  4. Click on Tomcat Manager; enter your admin user login and password (given when you installed Tomcat); click OK. If your login and password are correct, the Tomcat Web Application Manger page will appear.

  5. Under "Deploy directory or WAR file located on server" you should see a deploy button. You need not specify a path. If you simply click the delpoy button, Tomcat will automatically refresh it's list of applications. TomcatTest should now appear in the Applications list.

  6. Go to http://localhost:8080/TomcatTest/servlet/TomcatTest. Tomcat will run the servlet TomcatTest and print its output onto the web page. If the output is database information, all is well. If instead you see a message that an SQLException occurred, check that the MySQL server is running, that the test database with the correct user name, user password and table structure has been created. 

  1. Go to the tomcat installation folder and open the "webapps" folder (usually C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps ). This folder contains all the applications you plugged in so far into Tomcat. Open "TomcatTest" folder. Every file under this folder except for WEB-INF is a file directly accessible from a url such as http://localhost:8080/TomcatTest/MY_FILE_NAME. This folder usually contains all the static HTML content you might need for your web application. In our case we have "index.html". Now open the WEB-INF folder. This folder is not directly exposed on the internet. It actually contains your Java executable classes that provide dynamic content of your web application.

    The subfolder "classes" contains your Java classes, while the "lib" folder is used to store the libraries you might use in your Java classes. In the "lib" folder you will find the MySQL JDBC driver. Another very important file in this folder is "web.xml". This file contains description of all your Java servlets that you would use in your application. We have only one servlet in this application. If you open "web.xml" you will see description of servlet "TomcatTest". Without "web.xml" Tomcat would not know how to configure a the classes you have in the "classes" folder. In our case we declare that we have a servlet "TomcatTestServlet" which Java class is TomcatTest. We also specify that we map this servlet to path "servlet/TomcatTest", thus can be accessed at http://localhost:8080/TomcatTest/servlet/TomcatTest.

    Now let's look at the "sources" folder. If you make any changes to "TomcatTest.java", and recompile the program, we'd like those changes to be reflected the next time you reload your web application. To recompile the program your -classpath flag must contain paths to both: the MySQL driver and the servlet API jar file. Assuming you are inside the "sources" folder, the following command will recompile the servlet in DOS
javac -classpath ..\lib\servlet-api.jar;..\lib\mysql-connector-java-5.0.8-bin.jar TomcatTest.java
Be sure to place a copy of the TomcatTest.class file inside the WEB-INF\classes folder (i.e. you want to overwrite the old .class file with the one that you just created) You can go to the "Tomcat Manager" page and click on "reload" next to "TomcatTest". When you run the servlet now, you should see the desired changes in the functionality. More information on the servlet API is available at http://java.sun.com/products/servlet/2.2/javadoc/.

 

JSP example

Download and install  the jspTest.war file in a similar fashion to how you installed TomcatTest.war. Checkout its directory structure. Read the index.jsp file  and note where the mysql-connector-java-5.0.8-bin.jar file is stored.

Then use your browser to open the link:

     http://localhost:8080/jspTest/index.jsp

which will activate the JSP page.  It will talk to your local MySQL database.
To learn more about JSP using examples, check:

http://java.sun.com/products/jsp/html/jspbasics.fm.html





Servlet Session examples

Session.war   ShowItems.java  ShowSession.java

Install the Session.war and test the following requests:

Step by Step

Here are the recommended steps you can follow to accomplish for this project:
  1. Setup the Tomcat Programming Environment;
  2. Using the JSP and/or Java Servlet examples above, make a sample Java servlet program and/or jsp program work in your environment. The program should be able to talk to your database server using JDBC;
  3. Implement the "Login" Page;
  4. Implement the "Search" Page;
  5. Implement the "Movie list" page, including the "Sorting" and "Prev/Next" features;
  6. Implement the "Single Movie" page;
  7. Implement the "Single Star" page;
  8. Implement the "Browsing by movie genre" page;
  9. Implement the "Browsing by movie title" page;
  10. Add a "Add to Shopping Cart" button to each movie on all pages;
  11. Add a "Checkout" button to all pages;
  12. Implement the page to do checkout.

JDBC connection Pooling

These instructions apply to configuring Apache Tomcat 5.5 webserver to enable connection pooling and will closely follow the example on Tomcat's JNDI datasource example at the link provided in step 1.
  1. Go to the section titled " MySQL DBCP Example " on this webpage http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
  2. Follow the instructions under " 1. MySQL configuration ". You can use 'testuser' and 'testpass' instead of 'javauser' and 'javadude' as username and password respectively. Insert the row as indicated.
  3. We'll create web application named DBTest. For now just create a folder named DBTest with the necessary directory structure required of web applications as explained in the FAQs on project 1 . If you are unsure of the structure, just download the TomcatTest.war example and deflate it. Then, remove all class files and source files, and rename the folder as "DBTest".
  4. Create an empty file named context.xml inside the META-INF folder.
  5. For the 2nd step " 2. Context configuration " the document explains different ways in which you can setup the "CONTEXT" for your web application. Follow the link and read a bit about "Contexts" in web applications. We have tested it by adding to the context.xml file inside the META-INF directory of the web application. So create an empty context.xml file inside the META-INF folder
  6. Copy everything from the < Context > tag to < /Context > tag in the example shown on the web site. Paste this into the "context.xml" that you just created in the META-INF folder. Remember to change the 'username' and 'password' under the < Resource > tag
  7. Create a web.xml file as shown in the 3rd step " 3. web.xml configuration ". (Overwrite the file if you are using the TomcatTest example as a placeholder).
  8. Follow the 4th step " 4. Test Code " as indicated. The jar files they refer to are available here: standard.jar and jstl.jar . Place these jar files inside DBTest/Web-INF/lib folder. Make sure 'servlet-api.jar' and 'mysql-connector-java-5.0.8-bin.jar' are also present in the lib folder
  9. Deploy the application (place the DBTest directory under the web-apps folder of Tomcat installation). Deploying web applications was discussed above under Installting Tomcat . Type the url http://localhost:8080/DBTest/test.jsp and you should see the data that you just inserted in your toy database.


Deliverables

Please submit all the required files (*.class, *.jar, *.jsp, *.html etc) to run your program as WAR. In addition, include any source files (*.java) under WEB-INF/sources. If your project does not compile/run, it will get a very low score. .



Grading Criteria




Demonstration

To prepare for the demo, have the WAR file you turned in stored on your demonstration machine, and also have it deployed via Tomcat so that the FabFlix web site is ready to use. Have the MySQL server up and running;  When the demo begins, we will ask you to demonstate the three procedures discussed above, using the customer web site (from the WAR file) and the employee back-end program from Project 1. As before, your task is to convince us, in no more than 20 minutes, that your work is correctly and completely done and the FabFlix project is ready to move on to phase 3.



This project was first drafted by Chen Li and Kirill Petrov in Winter 2005. It was modified by the following contributors: Norman Jacobson and Kirill Petrov (Spring 2005); Norman Jacobson, Chen Li, and Michael Sirivianos (Winter 2006); Chen Li and Michael Sirivianos (Spring 2006); Chen Li and Shengyue Ji (Winter 2007); Chen Li and Chaitanya Desai (Spring 2008)