HW#2 --- last modified
January 01 1970 00:00:00..
Solution set.
Due date: Mar 1
Files to be submitted:
EmailServlet.java
EmailServlet.java
Purpose:
To write a simple servlet. To use some
of the
classes in java.util we've discussed.
Specification:
For this homework you will write an HTTPServlet to add email
addresses to an existing flat file of student data. Initially,
when no form data has yet been sent to your servlet, your servlet
writes out the HTML to display a page that looks like:
After this it reads in the file CS100.txt, which, to keep things simple,
lives in the same directory as the servlet. (Do not hard code where the
servlet is! Use the HttpServlet method getServletContext().getRealPath(""); to
figure it out dynamically). You should use one of the storage data
structures we learned about in java.util.* to store the data from
CS100.txt. For example, you could use an ArrayList. CS100.txt has rows
which consists of items enclosed quotes separated by tabs (this makes it
easy to read into Excel). The first row contains meta data about the file. It
might look like:
"Name" "StudentID" "EMAIL" "HW1" "HW2" "HW3" "HW4" "MID" "FINAL"
Note: The actual format of first row may contain more items and the
items in different positions, but it is guaranteed to have
"StudentID" and "EMAIL". This meta row specifies which column in
the rest of the rows has what data. A typical row in the rest of
the file might look like:
"Chris Pollett" "000-00-0000" "" "5" "6" "8" "9" "20" "40"
Your servlet should find the row which corresponds to the submitted
ID. It then should update the value of the EMAIL column in this row,
save the updated data back out to the file CS100.txt, and output a
page that looks like:
CS100 Email Collector
Your e-mail has been updated. Have a nice day!
|
If the studentID did not correspond to a row in the file your
program should output a page:
CS100 Email Collector
Invalid ID. Please contact the professor
|
Point Breakdown
Departmental coding guidelines for Java followed | 1pt |
Submit page outputs and displays ok |
1pt |
CS100.txt read in correctly | 1pt |
Data stored in a java.util.* data structure like ArrayList | 1pt |
Search of the StudentID works according to which column of the
meta row has StudentID | 1pt |
Email item updates correctly | 1pt |
Data writes back correctly to CS100.txt file | 2pt |
Invalid ID page generated if ID is not in CS100.txt | 1pt |
Email has been updated page display correctly | 1pt |
Total | 10pts |
|