CIT 597 Assignment 6: Calculator Servlet
Fall 2008, David Matuszek

Purposes of this assignment:

General idea of the assignment:

Write a web application that functions as a simple hand calculator, but also keeps a "paper trail" of all your previous work.

Use the MVC (Model-View-Controller) design pattern. The servlet that receives the request is the controller; it calls another class, the model, to do the computations; and it forwards the results to JSP, which acts as the view.

Your program should consist of the following components:

A servlet

You need a servlet to get the request, call a model class to do the work, and forward the result to JSP to create the response page. This is the controller.

This servlet should use the Java Session Tracking API to keep track of the "paper trail" and the current value.

A class to do the computations

Write a model class to handle the computations. This will involve doing the arithmetical calculations, but also keeping track of previous computations and results. The model class does no I/O of its own.

A JSP page

The JSP page should create the HTML page from the information computed by the model class and forwarded to it by the servlet. It contains a trail of all the work you have done previously, for example something like this:

    + 2.5 = 2.5
    + 5.0 = 7.5
    * 3.55 = 26.625
    / -3.0 = -8.875

In addition, it should have the following HTML form elements: a text field in which you can enter numbers; add, subtract, multiply, and divide buttons; a clear button, to reset the current value (in the text field) to zero; and a clear all button, to reset the current value to zero and "erase" the paper trail (for when your page is getting too long and you want to start over).

Since the user should enter only numbers into the text field, use JavaScript to validate the numbers before you submit the form. (Hint: Google on "JavaScript validate input field".)

A deployment descriptor

Use as the name seen by the user.

Isn't this assignment kind, stupid?

In "real life," your servlet would either be:

We aren't doing any of those things , and without a database (yet--we may do a tiny bit of database work later), there really just isn't much to do with a web application that we can't do much more easily with an ordinary application.

Turning in the assignment

This assignment will be due by midnight, Wednesday October 29. Zip your complete webapps directory and submit it via Blackboard.