修改下述的例子,增加web功能
(1)提供登录页面Login.jsp;
只需要登录名与密码(可在程序中硬编码)
(2)图书列表页面
列出所有可出售的图书供用户选择;
图书只需给出图书名(可在程序中硬编码)
(3)提供购物车商品的管理页面:
能够向购物车中添加图书(从图书列表中选择);
能够删除购物车中的图书;
能够察看购物车中的图书信息
(4)用户可主动退出系统
一个EJB例子如下(购物车)
import java.util.*;
import javax.ejb.Stateful;
import javax.ejb.*;
@Stateful(mappedName="cart")
public class CartBean implements Cart{
String customerName;
String customerId;
List
//ArrayList
public void initialize(String person) throws BookException {
if (person == null) {
throw new BookException("不允许没有用户!");
} else {
customerName = person;
}
customerId = "0";
contents = new ArrayList
}
public void initialize(String person, String id)
throws BookException {
if (person == null) {
throw new BookException("不允许没有用户!");
} else {
customerName = person;
}
IdVerifier idChecker = new IdVerifier();
if (idChecker.validate(id)) {
customerId = id;
} else {
throw new BookException("无效的ID: " + id);
}
contents = new ArrayList
}
public void addBook(String title) {
contents.add(title);
}
public void removeBook(String title) throws BookException {
boolean result = contents.remove(title);
if (result == false) {
throw new BookException(title + " 不在购物车中。");
}
}
public List
return contents;
}
@Remove()
public void remove() {
contents = null;
}
}
可以通过Baidu Hi通知我
有时间可能完成你所面临的任务
一样的要求也可能通知我
ES:\\A6D943CE0E4C2C724D148628817F86D5
你是哪个年级的?几班的?