CGS4854 Homework 2
Due Friday, 10/25 (late 6am, 10/26)
If you had any errors in previous homework, then fix them, so that you don't lose
points twice for the same mistake.
This assignment will take longer. I recommend that you start it early.
Enhanced Controller
Create a new package for this assignment in your username web app. It should
start with the same fields, pages and validations that were required for
the previous homework. If you were missing any requirements for the last
homework, add them and fix them for this homework.
- Do not change the files that were used for the previous homework.
- Previous assignments should still be accessible from the web app.
- You may copy files from previous assignments into this new package.
- You may import files from previous assignments, if they are unchanged. If you have to modify a file from a previous assignment, then make a copy of it in the current package.
- Modify the application so that it implements all the features from
Chapter 4. Review the steps in the tutorials for Chapter 4.
- The
shared
package will contain the files that can be shared by all web applications.
- Note that
HellperBaseCh4
should be placed in the
shared
package.
- Add all the necessary JAR files to the Libraries folder in your NetBeans project.
- Set up the log file properly.
- Create the error log file in the
WEB-INF/logs
folder.
- Edit
web.xml
and add the servlet definition for
InitLog4j
. Be sure it is called whenever the web app is
loaded.
- Bean
- Place the bean in the same package as the controller.
- Start with a copy of the bean that was used in the last assignment.
- Think of a calculation that needs to be done for your site. The
calculcation should include a double and an integer. Think of a
calculation that fits the theme of your site. Some examples might be:
- cost = price * quantity
- average price = cost / quantity
- total grade points = grade points * credits
- gpa = total grade points / credits
- total storage = megabytes * disks
- average storage = total megabytes / disks
- discount = total price * discout rate
- shipping cost = total pounds * rate
- handling fee = items * fee
- donation = months * amount
- Add a bean property that is a double. Use the value type double, not the wrapper class Double.
- This corresponds to the double that is used in your calculation.
- Add a bean property that is an int. Use the value type int, not the wrapper class Integer.
- This corresponds to the integer that is used in your calculation.
- The bean should implement default validation.
- Validate that one of the numeric fields is in a specific range of
numbers.
- Include an upper and lower
bound for the range of numbers.
- Do not include 0 in the range.
- Use a default value that is within the range of numbers.
- Validate that one of the string
properties only contains one of several words.
- Choose at least three words.
- Do not Hibernate.
- The match should not be case sensitive.
- Add an accessor that returns a double.
- There will be no mutator for this property (do not add a
setter).
- There will be no variable for this field. Do not add a
varible for this field in your bean.
- The accessor will return the result of the calculation.
- This type of accessor is known as a calculated field.
- Add a logger to the Bean
- Set the level of the logger to INFO.
- Write an info message every time the setter of one of your fields
is called.
- Modify the accessor from HW1 that creates a string which contains the
names and values of all the properties in the bean. Add all the new
properties and values to the string, except for the calculated
field. Do not include the value of the calculated field in this accessor.
- Controller Helper
- Use a unique name, other than "helper", to save the controller helper
in the session.
- Change the name of the
getData
method to another name
(it must start with get).
- Write a warning message to the logger every time
that the edit method is called. Include the value of the
editButton
from the query string in the message.
- Write an info message to the logger every time that
the copyFromSession method is called.
- Write a debug message to the logger every time the
process page is called. Include the value of one of the properties from
your bean in
the debug message.
- JSPs
- There should be no hidden fields in any of the JSPs.
- The JSPs should be in a hidden directory, but not in the same
directory as the controller. Move the JSPs to an appropriate
subdirectory of WEB-INF (not under classes).
- Modify all the EL statements so that they refer to the new name that
you used to store the helper in the session.
- Modify all the EL statements so that they do not use
data
, but use the appropriate name for the new accessor
method.
- Add a new field to the edit page that will hold a double. This field
will correspond to the new bean property that is a double.
- Add a new field to the edit page that will hold an int. This field
will correspond to the new bean property that is an int.
- For each of the numeric fields, display information in
the web page that indicates the range of acceptable numbers, so the user knows what to enter.
- In each JSP, call the accessor from the bean that displays all the names and values of the input.
- Echo the result of the calculation in the process page only.
Use the bean property that only has an accessor.
- Add a button and form to the process page, so the user can return to the edit page and modify the data.
- Run the application with different levels for the logger. You may change the level by modifying the web.xml file.
You may also change the
logger level in the constructor of the controller helper (do not
modify the
HelperBase
). Run the application with
level set to debug, then warn, then info, then error. Review the log file
after each run. View the log file in a separate editor, as NetBeans might
not re-read the file from the disk.
- Be sure there is a hypertext link in the
index.jsp
page to
the controller. Use a relative link.
- The web app must use the secure web.xml file and should only allow
you and me to access your application: Edit tomcat users
- Be sure to modify the project so that the .java files are placed
in the WAR file: Configuring WAR File
- After the app is running in NetBeans, upload it and run it on ocelot: Uploading a WAR file
Take a look at your log file, you will see that there are messages in it.
- Open the Files tab in NetBeans and navigate to
build ->
web -> WEB-INF -> logs
- Open the error log file. You should see lots of different messages.
Apache
Start your Apache server, if it is not running.
Modify the style sheet from Homework 1.
- Change the default style for the entire page.
- Change the color of the text. (part of HW1)
- Change the color of the background. (part of HW1)
- Change the font-family. Use at least three possible fonts; the
last font in the list should be a generic font family. Do not
include more than one generic font family in the list. (part of HW1)
- Set the size of the font so it is easy to read on all screens.
- Change the font so that it is either bold or italicized. (from EC4)
- Change the color for unvisited hypertext links. Use a color that is
different from the default text color for the page. (from EC4)
- Change the color for visited hypertext links. Use a color that is
different from the default text color for the page and different from
the unvisited hypertext link color. (from EC4)
- Be sure to validate the page and stylesheet at w3.org.
- Use the style sheet for all pages that can be accessed in this assignment,
including the error pages, all JSPs, all Apache files.
- Create a subdirectory of
docRoot
named cgs4854error
- Add an HTML page for 403 errors to this directory. Be sure it is a
valid HTML page. Use the style sheet in this page.
- Add an HTML page for 404 errors to this directory. Be sure it is a
valid HTML page. Use the styel sheet in this page.
- Do NOT add an index page to this folder.
- Configure Apache so that it uses your error pages for 403 and 404 errors.
- Add the following to the
index.html
page in the
docRoot
folder.
- Create a hypertext link to a file that does not exist.
- Create a hypertext link to a file named
.htaccess
. Do
not create this file, just create a link to it. Apache does not allow
access to such a file, even if it doesn't exist.
- Create a hypertext link to the
cgs4854error
folder.
- Create a hypertext link to the stylesheet.
- Change some icons on your server.
- Access the link
/icons/
from your Apache server
(be sure to include the trailing /). This is the
directory of icons that your server uses. This is a link to a shared
folder on ocelot, the folder is not located in your file system.
- Open the
icon.sheet.png
image. This has thumbnails
for all the images in the directory.
- Choose some images that you like. Remember the names of the images.
- Edit the
serverRoot/conf/srm.conf
file on ocelot.
- Change the image that is used for the parent directory. You
will need to examine the
srm.conf
file to see
which directive is used to set the image for the parent
directory.
- Change the image that is used for HTML files. Do not change the image
used for other text files.
- Remember to HUP your server after you make changes to the conf files.
ROOT Web Application
Be sure you have the following links in the ROOT/index.jsp file.
- Relative link to manager/html.
- Relative link to the root of your web application.
- Absolute link to your student host using your Apache port.
Submitting the Assignment
Clean and Build your web application. After doing this, navigate to
the WAR file in NetBeans and verify that the .java files are included: View WAR File
- Since you are using a log file that is in the web application, you will
need to shut down Tomcat before you can do a Clean and Build.
- Open the Services (Runtime in 5.5) folder and open the
Servers folder.
- Right-click the Tomcat server and select Stop.
- Now you can do a Clean and Build.
In the operating system (not in NetBeans) navigate to the dist folder in the
NetBeans project.
Deploy the WAR file on ocelot: Deploy a WAR File
- After deploying, open the
WEB-INF/logs
directory in winscp
or on ocelot.
- Change the permission of the error log file to 606. This
will allow Tomcat to write to the file.
- Use the manager to stop your web application and then start it again.
This will force it to reread the
web.xml
file so that the
logger can be initialized.
- Access your application and visit all the pages, then verify that some
new messages have been added to the log file.
To hand in the assignment, zip
the following directories into one ZIP file and upload it.
- Please zip the following. Issue a separate ZIP command for each.
All the files will be added to the same ZIP file.
- Remove the old zip file.
rm ~/username.zip
- Please use the following command to compress your
cgs4854/webapps/username folder.
zip -r username ~/cgs4854/webapps/username -x \*.jar \*.zip
\*.war
Replacing username with your user name. This will create a file
named username.zip. It contains the username web application.
- Please use the following command to compress your
cgs4854/serverRoot folder.
zip -r username ~/cgs4854/serverRoot -x \*.jar \*.zip
\*.war
Replacing username with your user name. This will add the serverRoot files to
the username.zip file.
- Please use the following command to compress your
cgs4854/docRoot folder.
zip -r username ~/cgs4854/docRoot -x \*.jar \*.zip
\*.war
Replacing username with your user name. This will add the docRoot files to
the username.zip file.
- Check the size of the ZIP file, it should be less than 3 MB. If it is
not, then you probably have another ZIP file stored in the ZIP archive.
Delete it and re-zip.
- You then have a choice for submitting the file.
- If you are logged onto ocelot, use my uploading program to upload the
file. Enter this command at the command prompt:
~downeyt/public/webftp/webftp.pl
- If you are using winscp, then download the zip file to your computer;
then, upload the file to me: Submitting
homework on-line via the Web.
- 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.