CGS4825 Assignment 2

Due Monday, 2/12 at 11:59 pm.

To hand in the assignment, zip your webapps directory and upload it from ocelot.

Be sure that all your files and subdirectories are included in the zip file.
After uploading, do not modify your files on ocelot until after your assignment has been graded.

JSP Controller

Implement the JSP Controller from the book in your ROOT web application. After getting it to work as it does in the book, make the following changes.

Servlet Controller

You are to create a new web application named book. You will use NetBeans to create the web application.

Using NetBeans

It is simpler to use NetBeans to implement the application on your local PC. Once it is running on NetBeans, it is a simple matter to get the application running on ocelot.

  • Create a new project in NetBeans.
    • On the first page of the project wizard, select the Web category and a Web Application project.
    • Do the following on the second page of the project.
      • Name the project book.
      • Select a location for the project. If you are in the lab, do not use the webapps folder as the location of your project. You may use the cgs4825 folder.
      • Be sure that the checkbox for Set Source Level to 1.4 is UNCHECKED. This is very important.
      • After making these changes, click Finish.
  • Modify the properties of the new web application.
    • Right click the name of the application and select Properties.
    • Open the Build folder and select Packaging. From the Exclude From WAR File text box, remove
      **/*.java,
    • Click OK.
  • Follow the following steps to create config files that you can edit.
    • Click on the Runtime tab.
    • Click on the + for the Server folder.
    • Right-click the Bundled Tomcat line.
    • Click on Edit Server.xml (Figure 1).
    • Close server.xml.
  • Add your username to the list of allowed users on the Tomcat used by NetBeans.
    • In the operating system, open the directory where Netbeans stores the files for Tomcat (Figure 2). \Documents and Settings\local-username\.netbeans
    • Navigate to the configuration directory for Tomcat on NetBeans. Your Tomcat may have a different version. Look for the folder that ends with _base.
      \5.0\jakarta-tomcat-5.5.9_base\conf
    • Edit the tomcat-users.xml file. This file identifies the usernames and passwords for users of Tomcat. This should agree with the username and password on ocelot. Add the following to this file.
      • Add a rolename for your ocelot username. Add this where all the other rolenames are located. Replace your-user-name with your ocelot user name.
        <role rolename="your-user-name" />
      • Add a user for your ocelot username. Be sure that this password agrees with the Tomcat password on ocelot. Add this where all the other users are located. Replace username with your ocelot user name and replace your-password with your password for accessing Tomcat on ocelot.
        <user username="your-user-name" password="your-password"
        roles="your-user-name,user,manager"/>
  • Copy the files for the Servlet Controller from the book's site into the appropriate directories in your web application.
    • Copy the JSPs into the correct subdirectory of the Web Pages folder in the NetBeans project window. The JSP files and directories for JSP files should be created in the Web Pages folder in NetBeans.
    • Copy the controller into the correct subdirectory of the Source packages folder in the NetBeans project window. Create the package in NetBeans and copy the servlet controller to the package directory.
  • Replace the web.xml file with the one from the ROOT web application on ocelot. Make the following changes.
    • Create a servlet definition for the controller servlet.
    • Create a servlet mapping for the controller servlet. Map the controller to the directory where the JSPs are located.
  • In the index.jsp page of the Web Pages folder, add two hypertext links: one to the directory where the JSPs are located and another to the controller servlet.
  • Run the application. The browser will open with the index.jsp page. Select the controller servlet link to run the application.Apache Server

Figure 1 Edit the servlet.xml file, then close it.


Figure 2 Location of tomcat-usere.xml

Deploying on ocelot

After the web application is running properly locally, deploy it on ocelot.

Upload and unpack the web application in ocelot.

Be sure that you can compile servlets on ocelot.

Apache Server

Modify the httpd.conf file as follows.

Modify the srm.conf file as follows.

Modify the contents of the docRoot folder as follows.

Modify the contents of the group folder as follows.

Useful links from the web site

NetBeans Information for Servlets
Uploading Files from NetBeans
Configuring ocelot for Compiling Servlets
Connecting Apache to Tomcat