该源码为JSP的开发案例集锦
源代码在线查看: buy.java
package ch4;
import java.util.Vector;
import java.util.Enumeration;
public class Buy {
Vector v = new Vector();
String submit = null;
String item = null;
private void addItem(String name) {
v.addElement(name);
}
private void removeItem(String name) {
v.removeElement(name);
}
public void setItem(String name) {
item = name;
}
public void setSubmit(String s) {
submit = s;
}
public String[] getItems() {
String[] s = new String[v.size()];
v.copyInto(s);
return s;
}
public void processRequest() {
if (submit.equals("add"))
addItem(item);
else if (submit.equals("remove"))
removeItem(item);
// reset at the end of the request
reset();
}
private void reset() {
submit = null;
item = null;
}
}