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.
-
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.
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.
-
Do not use NetBeans to create this part of the assignment. Create the files
directly on ocelot.
-
Add a page named WishList.jsp.
-
The whish list page will display the user's hobby, but will not allow the
user to edit it.
-
Add buttons to the wish list page that can send the user's data back to the
edit page or to the confirm page.
-
Add a button to the confirm page that can send the user's data to the wish
list page.
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. Detailed instructions about
using NetBeans are in the next section.
-
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.
-
Be sure to modify the project so that the .java files are placed in
the WAR file.
-
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
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.
-
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
Modify the httpd.conf file as follows.
-
Configure Apache so that all URLs that start with /book/ are handled
by Tomcat.
-
Configure Apache so that all URLs that end with .jsp are handled by
Tomcat.
-
Configure Apache so that all URLs that start with /manager/ are
handled by Tomcat.
Modify the srm.conf file as follows.
-
Change the name of the default page for a directory to cgs4825.html.
Add this to the front of the list for the current default pages.
-
Change the name of the default user directory to cgs4825/group. Replace
the name of the current user drectory.
-
Change the icon that is used for a directory. Go to the link /icons/
from your server to see a list of icons to use.
-
Change the icon that is used for the parent directory. Go to the link
/icons/ from your server to see a list of icons to use.
Modify the contents of the docRoot folder as follows.
-
Add a directory named fancy.
-
Do NOT add a cgs4825.html to this directory. When this directory is
viewed from the web, a directory listing should appear.
-
Add a file named README.html.
-
This file will not appear in the directory listing, but its contents will
appear below the directory listing.
-
Do NOT make this a complete HTML page. Only add your name to this
file.
-
Add a subdirectory named links.
-
Add a page named cgs4825.html. This page should appear by default
when your site is accessed.
-
Add a relative link (do not include the server and port) to the
Controller.jsp file on Tomcat.
-
Add a relative link (do not include the server and port) to the book
web application on Tomcat.
-
Add a relative link (do not include the server and port) to the
manager/html page on Tomcat.
-
Add a reletive link (do not include the server and port) to the fancy
directory.
-
Add a relative link to your group directory, ~your-user-name (do not
include the server and port).
-
Add a relative link to my group directory, ~tdowne99 (do not include
the server and port).
-
Validate this page at w3.org.
Modify the contents of the group folder as follows.
-
Add a page named cgs4825.html. This page should appear by default
when your group directory is accessed.
-
Add a relative link to the document root of your server. Do not put
docRoot in the link, it won't work.
-
Validate this page at w3.org.
-
In order for other students to access this page from their servers, be sure
the following permissions are set.
-
~ is 715
-
cgs4825 is 715
-
cgs4825/group is 715
-
cgs4825/group/cgs4825.html is 644
-
All other directories should be 705.
-
All other files should be 604.
Useful links from the web site
NetBeans Information for Servlets
Uploading Files from NetBeans
Configuring ocelot for Compiling Servlets
Connecting Apache to Tomcat