Homework Assignments

Homework 3

Downloads: Sample Files

In this assignment you are to add the following functionality to your CS320 Blog:

  • View All Blog Posts (and Comments for Extra Credit)
  • Add a New Blog Post
  • Comment on a Blog Post (Extra Credit)

This functionality should utilize the MVC programming paradigm in conjunction with a MySQL relational database. Begin by modifying the Welcome page that you created in Assignment 2 to display all Blog Posts on the site with the newest blog post displayed first. Here is a sample Welcome page. Note: you are not required to display comments to earn full credit on this assignment.

If a User clicks the 'Write a Post' link near the top of the page, they should be re-directed to a page like this. The User will type their post in the provided textarea. Upon submitting the post, your application should validate the post. The post should be considered valid if the length of the text (excluding white-space) is greater than zero (0). If the post does not validate you should re-display the Form with an error message. If the post validates, your application is to store the post to a MySQL database, and re-direct the User back to the main Welcome page. The main welcome page should now display the User's post along with all other posts on the site.

Your implementation should consist of a WelcomeController, WelcomeView, NewPostController, and NewPostView. Your views should not contain any scriptlets, and all data must be stored and retrieved from a MySQL database.

Extra Credit

Users of your Blog may want to comment on posts made by other Users. To do so you must first implement "Comment" functionality. Begin by displaying a hyperlink below every post that reads 'Add a Comment'. Use the Welcome page as a reference for the layout of the link.

When a User clicks on an 'Add a Comment' link, they should be re-directed to an Add a Comment page. Notice that the page displays the Blog Post that the User is commenting on, as well as a Form with a textarea where the User can enter their comment text. Upon submitting the Form, your application should validate the comment. If the length of the text (excluding white-space) is greater than zero (0), then the comment should be considered valid. If the comment does not validate, re-display the Form with an error message. If the comment validates add it to a MySQL database and re-direct the User back to the main Welcome page. The main Welcome page should now display the newly added comment below the Blog Post that was commented on.

Your 'Comment' implementation should consist of a CommentController and a CommentView. All data should be retrieved and stored from a MySQL database, and no scriptlets should be used in any view.

Grading

BlogPostBean

  • (5pts) Implementation

CommentBean

  • (5pts) Implementation

WelcomeController

  • (15pts) Retrieve all Blog Posts from database
  • (Extra Credit: 10pts) Retrieve all comments from database

WelcomeView

  • (10pts) Display all Blog Posts with the look/feel shown in the provided Welcome.html document
  • (Extra Credit: 10pts) Display all comments formatted to match the example provided in Welcome.html

NewPostController

  • (5pts) Validate new post form data
  • (15pts) Insert new post into database

NewPostView

  • (5pts) Layout
  • (5pts) Display error messages

Total: 65 pts

Extra Credit

CommentController

  • (10pts) Retrieve Blog Post being commented on
  • (5pts) Validates new Comment
  • (10pts) Commit new comments to the database

CommentView

  • (5pts) Display the blog post being commented on
  • (5pts) Layout
  • (5pts) Display error messages

As usual, upload all files to CSNS prior to the due date/time, as well as an Assignments.html document linking me to your working demo on the CS3 server.

NOTE: Homework1 and Homework2 should still work after you deploy homework 3. Do not overwrite Homework2. Instead, deploy homework 3 to a separate folder and ensure that you do not have Servlet or Bean naming conflicts.

Due by December 11, 2010 - 11:59PM

Homework 2

Now that students can register to use your site, they need a way of logging-in. In this assignment you are to create a Login Page that will authenticate a User based on a username and password combination. To accomplish this you will need to modify your code from Homework 1. When a User successfully completes registration, you should create a User object and store it to a list of Users that is accessible from any Servlet on your site. The User class should have the following String properties:

FirstName
LastName
Email
Phone
Year
Major
Username
Password

You may add additional fields at your discretion.

Next, you are to create the following three (3) servlets:

LoginServlet

The "LoginServlet" should match the appearance of the page located here. It will prompt a User for their Username and Password. It will also allow the User to check a box if they wish to remain "logged in" even after they have closed their browser window. Finally, the page will allow the User to submit their credentials, or link directly to the Registration Page you created in Homework 1.

The LoginServlet will also be responsible for displaying error messages in the case of the following two (2) events:

  1. Invalid username and password
    • Occurs when a User enters an invalid username/password combination.
  2. A User requests a page that requires a User to be logged in
    • Occurs when a User enters the URL of a restricted page without first authenticating using the Login Servlet.

AuthenticateServlet

The AuthenticationServlet will only be used for checking the supplied Username and Password against the List of Registered Users. This servlet will not generate any HTML. The AuthenticationServlet expects two parameters: username and password. If one or both parameters are missing, AuthenticationServlet should redirect the User back to the LoginServlet without displaying any error messages.

If the Username and Password are present, and a User is found with matching credentials, AuthenticationServlet should store the User's information in a Session object, and redirect the User to the WelcomeServlet. If the Username/Password combination do not match any Registered User, AuthenticationServlet should redirect the User back to the LoginServlet with error message 1 from above. That is to say, the User should see a LoginServlet that looks like this when they enter an invalid username and/or password.

If a third, optional paramater named rememberMe is present and set to true, AuthenticationServlet should implement some facility for remembering the User even after the User's browser has been closed. That is to say, your app should be able to identify and authenticate a User without the User having to "Login".

WelcomeServlet

The WelcomeServlet should look like the page located here. The actual content of the page will not be generated until Homework 3, so for now it should consist of a simple "Under Construction" image. However, the WelcomeServlet should not be visible to Users who have yet to authenticate. In other words, if a User has not logged in, and is not "remembered" by your site, they should not be allowed to view WelcomeServlet. Instead, when a non-authenticated User requests WelcomeServlet, they should be redirected to the LoginServlet with error message 2 from above. That is to say, they should see a login page like the one here.

You should notice the new "LoginStatus" bar located at the top of WelcomeServlet. It displays the message "Welcome, FIRSTNAME LASTNAME", where the User's first and last name are replaced accordingly. Next to the welcome message is a link that, when clicked, sends the User to the login page and effectively logs the User out of your site. This "Logout" should occur in the LoginServlet. Note, not only should the current Session be terminated when the User logs out, but if the User had requested your site to "Remember Me", the facility that was implemented to remember them should also be removed.

Grading

LoginServlet

  • (15pts) Layout and Design match sample above
  • (20pts) Error messages are displayed correctly
  • (30pts) Logs Users out

AuthenticationServlet

  • (20pts) Redirects with error to LoginServlet when Username/Password are invalid
  • (10pts) Redirects to WelcomeServlet when User successfully authenticates
  • (20pts) Utilizes Sessions when required
  • (20pts) Utilizes Cookie(s) to "Remember" Users

WelcomeServlet

  • (15pts) Layout and Design match sample above
  • (30pts) Redirects with error to LoginServlet when Users that are not authenticated request the page
    • Note: Users can authenticate in two ways: 1. via the LoginServlet, and 2. via the facility you implemented to "Remember Me".
  • (10pts) Correctly logs the User out when "Logout" is clicked

Assignments.html

  • (5pts) Include a direct link to each of the three (3) Servlets above
  • (30pts) Create a heading and paragraph for each Servlet created in this assignment, and describe how each feature of the servlet was implemented.

CS3 Demo

  • (-50pts) Your working Homework 2 must be deployed to the CS3 Server prior to the assignment due date and time. If it is not, you will receive a deduction.

As always, all source (java, css, html, js, png, gif, etc...) and compiled (class) files must be submitted to CSNS by the due date and time. If you fail to upload your source code you will not receive credit for this assignment. You must also deploy your working assignment to the CS3 server prior to the due date and time.

All example HTML, JS, and CSS files can be downloaded here.

Due by November 3, 2010 - 11:59PM

Homework 1

This quarter we will be creating a CS320 Blog. This blog will allow students to post questions and responses for all to view. Before allowing students the privilege of posting on your Website, you must require them to create an account through a registration page.

In this assignment you are to create the registration page located here.

The User is required to fill out all fields correctly. If the User submits the form with empty or incorrectly filled fields, you should re-display the form with the appropriate errors. An example of what I am looking for can be found here.

If the User submits the form, and all fields validate, you should display a page that looks like the one found here. Be sure to substitute 'John' with the User's first name.

Requirements

All HTML content should be generated dynamically using a SINGLE SERVLET named 'RegisterServlet'. That is to say this one servlet is capable of generating the form with and without error messages, as well as the successful registration message.

'RegisterServlet' should be mapped to a homework1 folder like so:

http://cs3.calstatela.edu:8080/cs320stuXX/homework1/RegisterServlet

You are expected to use all CSS, JS, and HTML provided here. For those who are so ambitious, you are encouraged to modify the look and feel of the form, but this should be secondary to the assignment.

Grading

30pts - Form displays/behaves as expected
50pts - Validation and Error Messages
30pts - Successful Registration
30pts - A Single Servlet
10pts - Deployed to the correct path with the correct name

Total: 150pts

To receive credit for this assignment you must upload all Java, class, XML, Javascript, and CSS files that you used in your assignment to the CSNS Website. You must also deploy a working version of your application to the CS3 Server, and provide an HTML document linking to your working Web Application. Upload this HTML document to the CSNS Website as well.

***UPDATE: October 7, 2010 - 11:00AM***

Validation Requirements

Both first and last names must contain only alphabets.
Both e-mail address must match, and the value entered must match the pattern of an e-mail address.
The telphone number must consist of 10 numerals. Decimals and non-numeric values are not permitted.
A year and major must be selected.
The username must only contain alphabets.
The passwords must match.

Due by October 14, 2010 - 11:59PM

Announcements

CSNS All files must be submitted to CSNS prior to the due date/time.