package com.oristand.demo.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
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 com.oristand.demo.entity.Book;
import com.oristand.demo.entity.CartItem;
public class addBookToCart extends HttpServlet {
/**
* Constructor of the object.
*/
public addBookToCart() {
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 {
//not complete Simple show process
response.setContentType("text/html");
HttpSession session=request.getSession(false);
Book book=(Book)session.getAttribute("addBook");
//HashMap<String, CartItem> cart=new HashMap<String, CartItem>();//cart Object
HashMap<String, CartItem> cart=(HashMap<String, CartItem>)session.getAttribute("cart");
if(cart==null){
cart=new HashMap<String, CartItem>();
}
//first method
// CartItem item=null;
// if(cart.containsKey(book.getISBN()+""))
// {
// item=cart.get(book.getISBN()+"");
// item.setQuantity(item.getQuantity()+1);
// }else{
// item=new CartItem(book,1);
// }
// cart.put(book.getISBN()+"", item);
//
//second method
CartItem item=cart.get(book.getISBN()+"");
if(item==null){
cart.put(book.getISBN()+"", new CartItem(book,1));
}else{
item.setQuantity(item.getQuantity()+1);
}
session.setAttribute("cart", cart);
//request.getRequestDispatcher("/viewCart.jsp").forward(request, response);
response.sendRedirect("viewCart.jsp");
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @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 {
doGet(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JAVA项目---电子书店项目源代码 (120个子文件)
BookDao.class 3KB
addBookToCart.class 2KB
ConnectionBase.class 2KB
Book.class 2KB
showBookServlet.class 2KB
getBooksServlet.class 2KB
PublisherDao.class 2KB
CartItem.class 944B
Publisher.class 904B
BookBiz.class 749B
.classpath 444B
org.eclipse.wst.jsdt.ui.superType.container 49B
main.css 2KB
main.css 2KB
Thumbs.db 7KB
Thumbs.db 6KB
bn01~.gif 49KB
bn01~.gif 49KB
bk.gif 6KB
bk.gif 6KB
msn.gif 4KB
msn.gif 4KB
qq.gif 169B
qq.gif 169B
top01.gif 126B
top01.gif 126B
icon1.gif 104B
icon1.gif 104B
bnbg1.gif 92B
bnbg1.gif 92B
topbt5.gif 82B
topbt5.gif 82B
topbt1.gif 80B
topbt4.gif 80B
topbt3.gif 80B
topbt2.gif 80B
topbt1.gif 80B
topbt4.gif 80B
topbt3.gif 80B
topbt2.gif 80B
leftbg.gif 44B
leftbg.gif 44B
addBookToCart.java 3KB
showBookServlet.java 3KB
BookDao.java 3KB
getBooksServlet.java 3KB
ConnectionBase.java 2KB
Book.java 2KB
PublisherDao.java 898B
Publisher.java 592B
CartItem.java 551B
BookBiz.java 356B
1.jpg 74KB
bn01~.jpg 49KB
bn01~.jpg 49KB
bn01.jpg 39KB
bn01.jpg 39KB
ebechtp1.jpg 19KB
ebechtp1.jpg 19KB
advjhtp1.jpg 19KB
advjhtp1.jpg 19KB
iw3htp1.jpg 18KB
iw3htp1.jpg 18KB
chtp3.jpg 17KB
chtp3.jpg 17KB
cpphtp3.jpg 16KB
cpphtp3.jpg 16KB
jhtp3.jpg 16KB
jhtp3.jpg 16KB
vbhtp1.jpg 16KB
vbhtp1.jpg 16KB
xmlhtp1.jpg 16KB
xmlhtp1.jpg 16KB
javactc3.jpg 16KB
javactc3.jpg 16KB
jhtp2.jpg 15KB
jhtp2.jpg 15KB
iw3ctc1.jpg 14KB
iw3ctc1.jpg 14KB
perlhtp1.jpg 14KB
perlhtp1.jpg 14KB
vbctc1.jpg 13KB
vbctc1.jpg 13KB
cpphtp2.jpg 13KB
cpphtp2.jpg 13KB
javactc2.jpg 12KB
javactc2.jpg 12KB
top2.jpg 11KB
top2.jpg 11KB
top3.jpg 11KB
top3.jpg 11KB
chtp2.jpg 11KB
chtp2.jpg 11KB
top4.jpg 11KB
top4.jpg 11KB
top1.jpg 11KB
top1.jpg 11KB
cppctc3.jpg 8KB
cppctc3.jpg 8KB
design.jpg 7KB
共 120 条
- 1
- 2
资源评论
- 徙南鸟2018-12-18不知道怎么运行
- isudong2016-05-10还可以参考,功能有点简单
PhoenixSlade
- 粉丝: 28
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功