我做的一个很简单的sessionBean运行时出错了,不知道是为什么??请大虾进来看一下!解决后50分全部相送!!
这个就是我的有状态会话bean
package sessionbean;
import javax.ejb.*;
import java.rmi.*;
import java.lang.*;
import java.util.*;
import java.io.Serializable;
public class Enterprise1Bean implements SessionBean {
SessionContext sessionContext;
java.lang.String cardHolderName;
java.lang.String creditCardNumber;
java.util.Vector items;
public void ejbCreate(String _cardHolderName,String _creditCardNumber) throws CreateException {
cardHolderName = _cardHolderName;
creditCardNumber = _creditCardNumber;
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
}
public void ejbPassivate() {
/**@todo Complete this method*/
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public void addItem(Item item) {
System.out.println("\t addItem"+item.getTitle());
items.addElement(item);
}
public void removeItem(Item item) {
System.out.println("remove item"+item.getTitle());
Enumeration elements = items.elements();
while(elements.hasMoreElements()){
Item current = (Item)elements.nextElement();
if(item.getClass().equals(current.getClass())&&item.getTitle().equals(current.getTitle())){
items.removeElement(current);
return;
}
}
}
public float getTotalPrice() {
System.out.println("\t getTotalPrice:");
float totalPrice = 0f;
Enumeration elements = items.elements();
while(elements.hasMoreElements()){
Item current = (Item)elements.nextElement();
totalPrice +=current.getPrice();
}
return (long)(totalPrice*100)/100;
}
public void purchase() {
/**@todo Complete this method*/
}
}
这是客户端测试代码:
public static void main(String[] args) {
Enterprise1TestClient1 client = new Enterprise1TestClient1();
String cardHolderName = "jackb.d";
String creditCardNumber = "1234-123-34234-123";
client.create(cardHolderName,creditCardNumber);
Item knuthBook1 = new Item("the art of jsp",49.95f);
Item knuthBook2 = new Item("the art of book",49.95f);
client.addItem(knuthBook1);
client.addItem(knuthBook2);
client.removeItem(knuthBook1);
client.purchase();
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
}