Revision to Examples 18.12 and 18.13 to maintain greater separation of
Java
from HTML.
revised Example 18.12 OrderBean.java
//Copyright (c) 2000, Art Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* A JavaBean to hold values from a form request
*/
package order;
public class OrderBean {
private String name = "Name";
private String password = "Password";
private String flavor = "Flavor" ;
private String[] toppings = {"Toppings"};
private String place = "Place";
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
public void setPassword(String p) {
password = p;
}
public String getPassword() {
return password;
}
public void setToppings(String[] t) {
toppings = t;
}
public String[] getToppings() {
return toppings;
}
public void setFlavor(String f) {
flavor = f;
}
public void setPlace(String p) {
place = p;
}
public String getPlace() {
return place;
}
public String getFlavor() {
return flavor;
}
public String getResult() {
String s = "with ";
if (toppings == null)
s = "no toppings";
else
for(int i=0; i < toppings.length; i++)
if (i == toppings.length -1)
s += " and " + toppings[i];
else
s += toppings[i] + ", ";
if (place.equals("Eat here"))
s += " to eat here.";
else
s += " to go.";
return s;
}
}
Revised Example 18.13 PostOrderBean.jsp