CGS4825 Assignment 3
Section 01: Due 2/16 at 11:59 pm.
Section 02: Due 2/17 at 11:59 pm.
Create a new web app named hw3.
-
Add a new link in the ROOT/index.html to the root of this context.
-
Use the secure web.xml file. Edit it for your user name.
-
I have provided a class named downey.hw3.Utilities. Use the static
method in this class to copy a file to the browser. This class is included
in the downey.jar.
- Copy this jar file into the lib directory of your hw3 web app.
- You must get a new copy of this jar file.
- The path to this file on ocelot is
~downeyt/cs/public_html/cgs4825/jar/downey.jar
- View the JavaDoc for this jar file: Documenation.
-
I haved also uploaded coreservlets.jar
- It contains all the Utility classes from the coreservlets package.
- If you want to use it, copy it to your lib directory.
- The path to this file on ocelot is
~downeyt/cs/public_html/cgs4825/jar/coreservlets.jar
-
Edit the .cshrc file on ocelot, and add a path to the classes
directory of this web app. Also add a path to the downey.jar file. If you
want to use the coreservlets.jar file, then also add a path to it.
Then run the command
source ~/.cshrc
-
Once you have created the web app structure, add the web app to your host
using your manager.
-
Add an index.html in the root directory of the new web app.
-
Include all the tags for a well-defined web page.
-
Include a title.
-
Include your name.
-
Add a heading to the page.
-
Add a two-column table containing the following relative links. Each link
should be in a separate data element.
-
A link to your servlet with no path info nor query string.
-
A link to your servlet that will open the images/mozilla.gif file
from this web app.
-
A link to your servlet that will open the index.html file from this
web app.
-
A link to your servlet that will open the index.html file from this
web app. Display the file as text/plain, not text/html.
-
A link to your servlet that will display one of your sayings.
-
A link to your servlet that will generate the error that the index is out
of range.
-
A link to your servlet that will generate the error that the query string
is not a number.
-
Add an images directory in the hw3 directory. Add the following
images to this directory.
-
mozilla.png If you want to copy this from
ocelot, then the path
is
~downeyt/cs/public_html/cgs4825/images/mozilla.png
-
mozilla.jpg If you want to copy this from
ocelot, then the path
is
~downeyt/cs/public_html/cgs4825/images/mozilla.jpg
-
mozilla.gif If you want to copy this from
ocelot, then the path
is
~downeyt/cs/public_html/cgs4825/images/mozilla.gif
-
Add a servlet that will generate a dynamic web page as described below.
-
Place your servlet in a package of
your-user-name
-
Your servlet should be accessible from your Tomcat host port 8080 through
the URL
http://studentXX.cgs4825.cs.fiu.edu:8080/hw3/servlet/your-user-name.servlet-name
-
Your servlet will generate a dynamic page based on the Path Translated,
Query String, Remote User, User Agent, and Accept.
-
If the Path Translated header is not null, then do the following
-
Do not call getWriter, nor try to write any output to the browser,
except by calling my copyFile method.
-
If the Query String is not null, then use the value
of the Query String as the content type that is sent to the browser.
-
If the Query String is null, then set the content type based
on the file's extension
-
.gif extensions should send a content type of
image/gif
-
.png extensions should send a content type of
image/png
-
.jpg or .jpeg extensions should send a content type of
image/jpeg
Note: image/jpeg not image/jpg
-
.html extensions should send a content type of
text/html
-
.txt extensions should send a content type of
text/plain
-
If the extension does not match any of these, then set the content type as
text/plain
.
-
Call my copyFile method with the Path Translated header to
copy the file to the browser.
-
If the Path Translated header is null, then do the following
-
If the Remote User header is not null, then display a personalized
header. Otherwise, display a generic header.
-
Display a phrase based on the User Agent header
-
If the User Agent header contains Mozilla (in any case) then
display the phrase
This browser is based on Mozilla
-
If the User Agent header does not contain Mozilla (in any case)
then display the phrase
This browser is not based on Mozilla
-
Display an image based on the Accept header.
-
If the Accept header contains image/png ,then display
mozilla.png
from the images directory of the web app.
-
Else if the Accept header contains image/jpeg, then display
mozilla.jpg
from the images directory of the web app.
-
Else if the Accept header contains neither of the above, then display
mozilla.gif
from the images directory of the web app.
-
Create an array of strings as a member variable in your servlet. This array
will be shared by all threads. The array should contain at least 6 famous
sayings. You may not use any of the sayings that I used in my example for
this assigment.
-
Include all the tags for a standard HTML page.
-
If the Query String equals all (in any case), then display
all the sayings from the array.
-
If the Query String does not equal all (and is not null), then
interpret the Query String as an index into the array
-
If the Query String is not a number, then display a specific error
for this.
-
If the Query String is a number, but is not in range, then display
an error message and inform the user of the correct range.
-
If the Query String is a valid index, then display the saying at that
position in the array.
-
Test your servlet on
-
IE
-
Mozilla or Firefox
-
Test locally using Webclient from the textbook. Create a local web app that
does not require a password to access. Use Webclient to set the headers.
-
I have an example running at
http://student01.cgs4825.cs.fiu.edu/~tdowne99
You will need to enter your ocelot username and Tomcat password in order
to access this site.