Now that the basics are done with, it's time to begin applyingthat theory to Web development. This week, The JSP Files investigates theJSP Request object, and demonstrates how it can be used to process formdata. Learn about JSP's array variables, find out what chocolate chipcookies and couch potatoes have in common, and explore a very unusualpharmacy.
Just as you can access data from text fields, you can also use the getParameter() method to evaluate the state of radio buttons and list boxes. Suppose you modify the form above to something a little more complex.
<html><head><basefont face="Arial"></head><body><center><%// pills.jsp// define the variables and assign valuesString colour = request.getParameter("colour");String quantity_string = request.getParameter("quantity");// convert string to numberint quantity = Integer.parseInt(quantity_string);// process and display// who needs green pills?if (colour.equals("blue")){out.println("Sorry, we don't carry blue pills here.");}else{ if (quantity >= 50) { out.println("Stocking up, are we?"); } else { out.println("Here you go. And would you like fries with that?"); }}%></center></body></html>
Depending on the combination of pill type and quantity, an appropriate message will be displayed.
As you can see, evaluating radio buttons and list boxes is almost exactly the same as evaluating regular text fields.
Before moving on to the other form constructs - namely, checkboxes and multiple-select list boxes - you need to understand a new type of variable: the JSP array.