CSCI.4220 Network Programming
Fall, 2006, Lab 5 Tomcat, JSPs, and Javabeans


Part A: Create an HTML page which displays some information about plants for sale. It should look sort of like this

Item Price Quantity
Rhododendrons $18.50
Tea Roses $6.95
Marigolds $1.29

The page should be in an HTML form which allows the user to place an order for each of the three types of plants. A user can order any amount of any of these. The order should be sent to a jsp file with embedded scriptlets which calculates the cost for each suborder and the total cost of the order and sends this back to the client.

For example, if the user ordered 50 rhododendrons, 0 tea roses, and 100 marigolds, the returning web page would look like this

Item Price Quantity Total
Rhododendrons $18.50 50 $925.00
Tea Roses $6.95 0 $0.00
Marigolds $1.29 100 $129.00
Total     $1,054.00

Part B: Once you have this working, redo the jsp page so that it does all the work in a java bean. Your jsp file cannot have any scriptlets in it.

You need to convert a string to a double. Here is some code to do this.

import java.text.*;

try {
    NumberFormat nf = NumberFormat.getInstance();
    double Value = nf.parse(amount).doubleValue();
    // amount is the string which represents the number
    // Value is the double
   ...
} 
catch (ParseException e) 
{  ... }

A real application would have to do lots of error handling, such as empty strings; but you do not have to worry about this; you can assume that the user will enter valid numbers for all three fields.

Hint: Particularly for the bean, you may have to stop and restart tomcat to get your application to work properly.