📄 balanceaction.java
字号:
package shopping.action;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.List;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import shopping.form.OrderActionForm;
import shopping.form.InitialBookForm;
import bookstoreejb.*;
public class BalanceAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
HttpSession session =httpServletRequest.getSession(false);
List cart =(List)session.getAttribute("cart");
if(cart==null)
System.out.println("cart is null");
if(cart.size()==0)
System.out.println("cart size is 0");
System.out.println("cart size is:"+cart.size());
OrderActionForm orderActionForm =(OrderActionForm)actionForm;
StringBuffer stringBuffer = new StringBuffer();
String bookList=null;
float price=0;
float singlePrice=0;
for(int i=0,j=cart.size();i<j;i++){
InitialBookForm initialBookForm =(InitialBookForm)cart.get(i);
stringBuffer.append(initialBookForm.getBookname());
System.out.println("book name in balanceAction is:"+stringBuffer.toString());
stringBuffer.append(";");
Float temp = new Float(initialBookForm.getPrice());
singlePrice =temp.floatValue();
price = price +singlePrice;
}
bookList = stringBuffer.toString();
bookList = bookList.substring(0,bookList.length()-1);
System.out.println("the book list in balance action is:"+bookList);
Order order = new Order(orderActionForm.getOrderId(),
orderActionForm.getCustName(),
orderActionForm.getAddress(),
orderActionForm.getPersonalEMail(),
bookList,
price);
try {
InitialContext initialContext = new InitialContext();
Object object = initialContext.lookup("facade");
facadeHome fHome = (facadeHome) PortableRemoteObject.narrow(object,
facadeHome.class);
facade facadeInstance = fHome.create();
facadeInstance.sendMessage(order);
session.removeAttribute("cart");
}catch (javax.naming.NamingException namingException) {
namingException.printStackTrace();
}
catch (java.rmi.RemoteException remoteException) {
remoteException.printStackTrace();
}
catch (javax.ejb.CreateException createException) {
createException.printStackTrace();
}
return actionMapping.findForward("initial");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -