CGS4854 Homework 4
Due Friday 12/6 (late 12/7 at 6am)
The homework assignments are cummulative. This homework must include the requirements form previous assignments, like the bean using a log file, writing messages to the log files, calculated fields, Apache configuration ...
If you had any errors in the previous homework, then fix them, so that you
don't lose points twice for the same mistake.
Apache
Start your Apache server.
- Modify the style sheet from previous assignment.
- Limit access to the
styles
directory to you and to me. Limit access before you create your
style sheet. I do not want anyone but you and me to be able to see your style sheet at any time.
- Change the default style for the entire page.
- Change the color of the text to something other than black.
- Change the color of the background to something other than white.
- 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.
- Set the font size
- Change the default style for the
input
and
select
tags.
- Use a
monospace
font.
- Use the
font-family
tag.
- Choose at least two specific fonts and a generic font.
- The last option in the list of fonts should be for the
generic font.
- Make the font 15% larger than the default font for the page. Use a
relative measurement.
- Change the text color to a different color than the rest of the page.
- Change the background color to a different color than the rest of the page.
- Change the default style for the
code
tag.
-
Use a relative size to make the size of the text 10% smaller than the default font for the page.
If the font is tiny, then you did something wrong.
- Use a different background color than any of the other background colors on the page.
- Create a style named
danger
that can only be used
with code
tags.
- Use a relative size to make the size of the text 20% larger than the body font.
Be sure you didn't make it smaller.
- Underline the text.
- Make the text bold.
- Change the default ordering that is used for
ol
tags.
- Do not change the style for any
li
tags.
- Do not create a named style.
- Choose one of upper-roman, lower-roman, upper-alpha, lower-alpha.
- Change the default ordering for nested
ol
tags
(ol
tags inside ol
tags).
- Do not change the style for any
li
tags.
- Do not create a named style.
- Choose one of upper-roman, lower-roman, upper-alpha, lower-alpha,
decimal (different from the ol ordering).
- Create a style named
narrow
that can only be used with
paragraphs.
- Set the right margin. Use a relative measurement based on the
height of the letter 'M'.
- Set the left margin. Use a relative measurement based on the
height of the letter 'x'.
- Offset the first line of text from the margin.
- Change the default styles for
h1
and h2
tags.
h1
and h2
headings should use a
different font than the body. Use the font-family attribute and
specify a very specific font, a more common font and a generic
font. All of these must be different from the default fonts for the
page.
h1
and h2
headings should have center
alignment.
- Change
h1
headings as:
- Capitalize all letters in the heading
- Declare a background image for the heading.
- Be sure the text color contrasts with the background
image.
- Turn on italic.
- Change
h2
headings as:
- Capitalize the first letter of each word.
- Turn off the default bold style.
- Change the text color.
- Turn on underline.
- Change the default style for unvisited hypertext links.
- Change the text color.
- Change the background-color.
- Turn off the underline.
- Make the font 5/6 the size of the the body font. Use a relative
measurement.
- Change the default style for visited hypertext links.
- Change the text color.
- Change the background-color.
- The other changes to the unvisited style will automatically cascade to this style.
- Use the style sheet in all pages that can be accessed from Apache (except the stylesheet, itself),
including error pages and all the files for your username web application on Tomcat (except
the manager).
- Modify the
docRoot/index.html
file.
- Add some h1 and h2 headings.
- Create one
h1
heading at the top of the page.
- Use several
h2
headings in the page. Place one
before each of your paragraphs in the page. Make sure your
paragraphs contain enough text so that the margin size can be
observered.
- Do not use a heading for an entire paragraph.
- A heading should contain just a few words.
- Use several
code
tags throughout the page.
- Use the
danger
style several times in the page.
- Use the
narrow
style on one of the paragraphs.
- Add a nested, ordered list of webapps and error links.
- The outer list should have three items: Style, Web Apps and Errors.
- Style will have a link to the stylesheet.
- Web Apps will have an inner list for the links to the manager and
username webapp (and tutorials, if you have them).
- Errors will have an inner list for the links that cause errors
(not found and forbidden) and the link to the error folder.
- Modify the error pages.
- Each error page should use the stylesheet.
- Add two headings to each page: h1 and h2.
- Add a small image to each error page. Use a src with a relative link from
the root of the server, so the images will appear from anywhere in the site.
Tomcat
Create a new package for this assignment in your username web app.
- Do not change the files that were used for assignment 3.
- Assignment 3 should still be accessible from the web app.
- You may copy files from assignment 3 into this new package.
- You may import files from assignment 3, if they are unchanged.
- Modify your application so that it can initialize and store complex form
elements.
- Add all the necessary files to the
shared
package.
- Note that
HellperBaseCh6
should be placed in the
shared
package.
- Add all the necessary JAR files to the Libraries folder.
The controller for this assignment is based on the Complex Persistent controller.
The bean is based on the bean from HW3, not from the Complex Persistent controller.
Step-by-step
instructions for the Complex Persistent Controller are available on the book's web site.
Bean
- Place the bean in the same package as the controller.
- Add annotations so that the bean can be saved to a database.
- Annotate the class so that it can be saved to its own table.
- Add a key field to the bean or extend it from
PersistentBase
.
- Mark any properties that only have accessors so that they are not
saved to the database.
- You have a choice of new properties to add:
- You may add a radio group and a multiple
selection list.
OR
You may add a checkbox group and a single
selection list.
- If you want to add even more properties, you may; however, you
must implement at least the two that I have specified in the
choices above.
- Add annotations:
- Mark any properties that return arrays so that they can be saved
to the database in a separate table.
- Add annotations for radio groups, checkbox groups and select
lists so that they can be initialized easily in a JSP.
- The bean should implement required validation.
- The name of the bean class should be different than the name for the
bean in any Extra Credit and any Homework.
- Validate that no more than three options from the checkbox group or
multiple selection list have been chosen.
- Look at the Hibernate
validations. There is one there that can help you.
- Remember that these types of elements are nullable: if
nothing is checked or selected, then there will be nothing in
the query string. You will also need to validate that it is not
null (size 0 is not the same as null).
- Validate that the radio group or single selection list has a
valid option.
- If the associated property in the bean is numeric, then use
min and max to validate the range of the value.
- If the associated property in the bean is a string, then user
a regular expression to validate it. Validate that it matches
one of the string values in the associated form element in the
JSP. You will also need to validate that it is not null (size 0
is not the same as null).
- For each field that is to be validated, display information in
the web page that indicates the correct format of the data to be
entered.
- Continue to implement all the validations from HW3.
- For all the other fields, you must implement either
required validation or default validation.
Controller Helper
- Create a hibernate config file and use the simplified
initHibernate
method.
- Use a unique name, other than "helper" and different than the one for
Extra Credit 6, to save the controller helper in the session.
- Change the name of the accessor for the bean to something other than
getData
.
- Modify
jspLocation
so that it returns the correct path
for JSPs.
- Write the current record to the database when the process button is
clicked.
- Do not retrieve records in this method.
- Write an information message to the log file containing the id of
the record that is being written to the database.
- Add a button method for the view page (described below). Read the
records from the database and make them available in the request for
next JSP.
- Do not save to the database in this method.
- Write a debug message to the log file that contains the number of
records that were retrieved from the database.
- Write a warning message to the log file if no records were
retrieved from the database.
- Treat
GET
requests as the start of a new transaction.
- Always show the edit page when a
GET
request is made.
- Do not read the old data from the session when a
GET
request is
made.
- Treat
POST
requests as the continuation of a transaction.
- Show the appropriate page based on the button that was clicked.
- Read the old data from the session and copy it into the bean.
- Use a name other than "database" to store the database records in the
request.
- When you are debugging your application, set the log level to debug.
When you submit the assignment, change the log level to error.
JSPs
- Use the Apache style sheet for all your JSPs.
- Add a h1 heading to each JSP
- 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 and the new name you used
for the bean accessor.
- Modify
Edit.jsp
- Use a table to organize the input elements so that they appear in
orderly columns. Place all the labels in one column and all the input
boxes in the second column.
- Be sure that your new input elements are initialized with the
values from the bean.
- Display error messages for all properties that are not valid.
Place all error messages inside a
code
tag with the
class set to danger
. The errors should stand out on
the page, based on your style sheet.
- Be sure that your new input elements are initialized with the
values from the bean. This means that radio groups and check box
groups should be checked according to the values that are in the
bean; the same is true for selection lists.
- Modify the confirm page.
- Use the
code
tag to display the values from the
bean.
- Use nested ordered lists to display all the data in
the bean. Those elements that return arrays will use the inner
nested list to display all its values.
- Modify
Process.jsp
.
- Use the
code
tag to display the values from the
bean.
- Use nested ordered list to display all the data in
the bean. Those elements that return arrays will use the inner
nested list to display all its values.
- Only display the current record from the bean.
- Do not display all the records from the database in this page.
- If you do not have one, add a button that returns to the edit
page to start a new request. When the edit page appears, the current
values should NOT appear in the input elements.
- Add a button that sends the user to the view page.
- Add a new page named
View.jsp
.
- Use a table to display all the data from the database.
- The first row in the database should use a
th
tag
for each column name.
- Use an unordered list to display those elements that have
multiple values.
- Add a button that returns to the edit page so the user can change
the values that were just saved. When the edit page appears, the
current values should appear in the input elements in the page.
- Add a button that returns to the edit page to start a new request.
When the edit page appears, the current values should NOT
appear in the input elements.
- Be sure to create a page named
Expired.jsp
.
- Include a friendly message informing the user that the data has expired
- Inlcude a form and a button so the user can start over.
- Inlcude an image.
General
- 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
Extra Credit
Extra credit is extra. After you have completed the assignment, you may add
features to it for extra credit. An assignment must have a grade of at least
90% before any extra credit will be assigned.
Extra Credit 7
Add the Account Login ideas to the homework controller. The Account Login pages
and logic can be added to any existing controller.
Extra Credit 8
You must complete Extra Credit 7 in order to complete Extra Credit 8.
Add the Account Cookie ideas to the homework controller. The Account Cookie pages
and logic can be added to any existing controller.
Extra Credit 9
You must complete Extra Credit 7 in order to complete Extra Credit 9.
Add functionality to the wish list page.
- Add a boolean property to the bean that indicates if the record in the database is for the wish list.
- When a bean is saved to the database from the process method, clear the new property.
- When a bean is saved to the database from the wish list method, set the new property.
- On the wish list page, show all the records for the current user that have the wish list property set.
- Display the wish list items in a table. Add a column with a button for each item. When the button is clicked,
set the current bean to that item and go to the confirm page.
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 delete your old ZIP file that you used to submit homework.
rm ~/username.zip
Replacing username with your user name.
- 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 ommand 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 folder to username.zip.
- 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 folder to username.zip.
- 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/cs/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.