package org.myrose.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.myrose.beans.BookCart;
import org.myrose.beans.Member;
import org.myrose.beans.Order;
import org.myrose.beans.OrderDetail;
import org.myrose.beans.Rebate;
import org.myrose.beans.VMember;
import org.myrose.dao.MemberDAO;
import org.myrose.dao.OrderDAO;
import org.myrose.dao.OrderDetailDAO;
import org.myrose.dao.RebateDAO;
import org.myrose.dao.VMemberDAO;
public class CartOrderServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public CartOrderServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
request.setCharacterEncoding("GBK");
}
/**
* The doPost method of the servlet. <br>
*
* 此方法用来生成定单操作
*
* 1 插入定单主表数据
* 2 插入定单明细数据
* 3 更新会员信息
* 4 更新会员等级
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
request.setCharacterEncoding("GBK");
String username=request.getParameter("username");
String truename=request.getParameter("truename");
String address=request.getParameter("address");
String postcode=request.getParameter("postcode");
String tel=request.getParameter("tel");
String pay=request.getParameter("pay");
String carry=request.getParameter("carry");
String email=request.getParameter("email");
String bz=request.getParameter("bz");
HttpSession session = request.getSession();
VMemberDAO vmdao = new VMemberDAO();
MemberDAO mdao = new MemberDAO();
OrderDAO orderDAO = new OrderDAO();
OrderDetailDAO orderDetailDAO = new OrderDetailDAO();
RebateDAO rdao = new RebateDAO();
VMember vm = new VMember();
Order order = new Order();
OrderDetail orderDetail = new OrderDetail();
Member m = new Member();
Rebate r = new Rebate();
vm.setUsername(username);
double rebate = 1;
try {
vm = vmdao.getVMemberByName(vm);
} catch (Exception e) {
e.printStackTrace();
}
if(vm != null){
rebate = vm.getRebate();
}
Vector cart = (Vector)session.getAttribute("cart");
int orderId = 0;
int temp = 0;
String grade = "0";
double price = 0;
double sum = 0;
double totalsum = 0;
double amount = 0;
boolean flag = true;
int bnumber = cart.size();
order.setBnumber(bnumber);
order.setUsername(username);
order.setTruename(truename);
order.setAddress(address);
order.setPostcode(postcode);
order.setTel(tel);
order.setEmail(email);
order.setPay(pay);
order.setCarry(carry);
order.setRebate(rebate);
order.setBz(bz);
try {
temp = orderDAO.addOrder(order).intValue();
//System.out.println(temp);
} catch (Exception e) {
e.printStackTrace();
}
if(temp == 0){
flag = false;
}else{
orderId = temp;
}
for(int i = 0;i < cart.size(); i++){
BookCart bookcart = (BookCart)cart.elementAt(i);
price = bookcart.getPrice()*rebate;
orderDetail.setOrderId(orderId);
orderDetail.setIsbn(bookcart.getIsbn());
orderDetail.setPrice(price);
orderDetail.setNumber(bookcart.getNum());
sum = price*bookcart.getNum();
totalsum = totalsum+sum;
try {
temp = orderDetailDAO.addOrderDetail(orderDetail).intValue();
} catch (Exception e) {
e.printStackTrace();
}
if(temp == 0){
flag = false;
}
}
m.setAmount(totalsum);
m.setUsername(username);
try {
temp = mdao.updateAmount(m);
} catch (Exception e) {
e.printStackTrace();
}
if(temp == 0){
flag = false;
}
try {
m = mdao.findMemberByNamePass(username, null);
} catch (Exception e) {
e.printStackTrace();
}
amount = m.getAmount();
r.setAmount(amount);
try {
r = rdao.getRebate(r);
} catch (Exception e) {
e.printStackTrace();
}
grade = r.getGrade();
m.setGrade(Integer.parseInt(grade));
try {
temp = mdao.updateGrade(m);
} catch (Exception e) {
e.printStackTrace();
}
if(temp == 0){
flag = false;
}
if(flag){
session.removeAttribute("cart");
request.setAttribute("order", "ok");
request.setAttribute("orderId", ""+orderId);
request.getRequestDispatcher("index.aspx").forward(request, response);
}else{
request.setAttribute("order", "no");
request.getRequestDispatcher("cart_checkout.jsp").forward(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ibatis jsp servlet 的网上书城项目 (188个子文件)
CartOrderServlet.class 6KB
BookServlet.class 4KB
Member.class 3KB
RegistServlet.class 3KB
BookInfo.class 3KB
OrderServlet.class 3KB
Order.class 3KB
PollServlet.class 3KB
AddCartServlet.class 3KB
ModifyCartServlet.class 3KB
SortBookServlet.class 3KB
BookInfoDAO.class 3KB
CheckCartServlet.class 3KB
LoadDataServlet.class 2KB
LoginServlet.class 2KB
ClearCartServlet.class 2KB
ForwardServlet.class 2KB
BaseDAO.class 2KB
VOrderDetail.class 1KB
LogoutServlet.class 1KB
MemberDAO.class 1KB
OrderDetail.class 1KB
Bbs.class 1KB
VMember.class 1KB
BookCart.class 1KB
Poll.class 1KB
OrderDAO.class 1KB
MyConn.class 1010B
PollDAO.class 942B
Rebate.class 923B
OrderDetailDAO.class 889B
VMemberDAO.class 667B
VOrderDetailDAO.class 641B
RebateDAO.class 626B
BbsDAO.class 497B
.classpath 840B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 2KB
index_06.gif 84KB
cart.gif 18KB
index_09.gif 11KB
VBxxxtkfsljx.gif 9KB
VFP200l.gif 8KB
ASPxxxtkfsljx.gif 8KB
VBgcyyysj.gif 8KB
Delphigcyyysj.gif 7KB
JSPgcyyysj.gif 7KB
VCgcyyysj.gif 7KB
ASPgcyyysj.gif 7KB
ASPsjkkfsljx.gif 7KB
Delphisjkkfsljx.gif 6KB
index_10.gif 6KB
PBsjkkfsljx.gif 6KB
VFPsjkkfsljx.gif 6KB
VBsjkkfsljx.gif 6KB
checkout.GIF 4KB
ico_cart.gif 4KB
ico_order.gif 4KB
index_14.gif 3KB
index_18.gif 3KB
index_16.gif 3KB
index_12.gif 3KB
reg.gif 3KB
bg_booksort.gif 3KB
index_ht.gif 2KB
ico01.gif 2KB
index_03.gif 2KB
T_mrbook.gif 1KB
ico_booksort.gif 1KB
freeze.gif 982B
folder.gif 933B
bg_Navigate.GIF 600B
enforce.gif 567B
thaw.gif 567B
greendot.gif 367B
Nav_separate.gif 261B
boardlist.gif 164B
modify.gif 121B
del.gif 109B
Cen_separate.gif 79B
bg.gif 52B
standard.jar 385KB
ibatis-2.3.0.677.jar 375KB
log4j-1.2.14.jar 359KB
msbase.jar 278KB
sqljdbc.jar 227KB
msutil.jar 58KB
jstl.jar 21KB
CartOrderServlet.java 6KB
BookServlet.java 6KB
RegistServlet.java 4KB
OrderServlet.java 3KB
PollServlet.java 3KB
CheckCartServlet.java 3KB
AddCartServlet.java 3KB
SortBookServlet.java 3KB
ModifyCartServlet.java 3KB
LoadDataServlet.java 3KB
Member.java 3KB
ClearCartServlet.java 3KB
共 188 条
- 1
- 2
资源评论
- 孟维龙2013-12-24还不错,稍加改动就可以运行起来。
- chaoyue20132013-12-02数据库是sqlserver,我用的是mysql,呵呵呵呵呵,谢谢,
- qy21332862013-01-04代码容易懂,但是不能直接运行..要自己根据环境改变一下
- dastone2012-06-07还不错的例子,但好像运行不了!不过感谢作者,可作为初步学习用!
- cmxyzx2013-03-05看起来还行,没有关键错误。数据库是sqlserver
ZhongWeicheng
- 粉丝: 137
- 资源: 327
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功