CGS4825 Assignment 2
Due Monday, 10/9 at 11:59 pm.
To hand in the assignment, zip your webapps directory and upload
it from ocelot.
-
Please use the following command to compress your webapps folder.
Change to your cgs4825 directory on ocelot and issue the command
zip -r username webapps -x \*.jar \*.zip \*.war
Replacing username with your user name.
-
Check the size of the ZIP file, it should be less than 1 MB. If it is not,
then you probably have another ZIP file stored in the ZIP archive. Delete
it and re-zip.
-
Use my uploading program from ocelot to upload the file.
~downeyt/cs/public/webftp/webftp.pl
-
Upload the file as binary.
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.
Servlet Controller
You are to create a new web application named book. You will use NetBeans
to create the web application.
-
Download all the necessary files for the Servlet Controller from Chapter
2 and get it working in your web app in NetBeans.
-
Get the servlet controller working as it is on the web site. Do not change
its package.
-
After the app is running in NetBeans, upload it and run it on ocelot.
-
The web app must use the secure web.xml file and should only allow you and
me to access your application.
-
Servlets in packages in the classes directory of the web application should
be able to be compiled on ocelelot.
-
After you get the controller working on ocelot, make a minor change to the
controller and recompile it.
-
To see the changes, reload the web app in the manager.
Using NetBeans
NetBeans Information for
Servlets
Uploading Files from
NetBeans
Configuring ocelot for Compiling Servlets
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.
-
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

\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.
-
Edit the web.xml file for the application.
-
Use the secure web.xml file for this application. Modify it so that you and
I can access your application. (You may copy your ROOT web.xml to this file).
When viewing the web.xml file in NetBeans, there are serveral options. Choose
XML from the menu bar at the top of the editor window to see the file as
plain text.
-
NetBeans supports XML tag completion. Type the beginning of a tag, then hit
CTRL-Space for completions.
-
Set cgs4825.jsp as the first choice for a welcome file. Each web
application has its own welcome page. Create a new cgs4825.jsp in
the Web Pages directory. This will be the page that is displayed when
the application is run.
-
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.
-
Create a new cgs4825.jsp file in the Web Pages directory. Add
a link to the directory where the JSPs are located and a link to the controller
servlet.
-
Run the application. The browser will open with the cgs4825.jsp page.
Select the controller servlet link to run the application.
-
Upload and unpack the web application in ocelot.
-
Upload the WAR file to your cgs4825 folder on ocelot, using an FTP
program. Do not upload it to the webapps directory, upload it to the
cgs4825 directory. Each time a web application is built in NetBeans,
a WAR file is created that has all the files of the web application stored
in the file structure of a web application. This file is located in the
Dist subdirectory of the project's folder.
-
Log into ocelot. Change to the cgs4825 directory and issue the following
command to unpack the WAR file into the webapps/book
folder.
unzip book.war -d webapps/book
-
Open the manager application from a web browser. You should see the book
web application listed.
-
Test that the application works.
-
Warning: Do not use the manager to deploy the WAR file. It will deploy it,
but you will not own the web application, so you will not be able to edit
the files on ocelot.
-
Be sure that you can compile servlets on ocelot.
Apache Server
Configure Apache so that all URLs that start with /book are handled
by Tomcat.
Connecting Apache to Tomcat