package com.zhy.servlet;
import com.zhy.entry.Book;
import com.zhy.entry.Car;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet("/carServlet")
public class CarServlet extends HttpServlet {
Map<String, Car> carMap= null;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession();
List<Book> bookList = (List<Book>) session.getAttribute("bookList");
int id = Integer.parseInt(req.getParameter("id"));
carMap = (Map<String, Car>) session.getAttribute("carMap");
if(carMap==null){
carMap=new HashMap<String, Car>();
Book book = bookList.get(id);
Car car = new Car();
car.setBookName(book.getBookName());
car.setPrice(book.getPrice());
car.setCount(1);
carMap.put(book.getId()+"",car);
}else {
if(carMap.get(id+"")!=null){
Car car = carMap.get(id+"");
car.setCount(car.getCount()+1);
carMap.put(id+"",car);
}else {
Book book = bookList.get(id);
Car car = new Car();
car.setBookName(book.getBookName());
car.setPrice(book.getPrice());
car.setCount(1);
carMap.put(book.getId()+"",car);
}
}
session.setAttribute("carMap",carMap);
resp.sendRedirect("jsp/car.jsp");
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
project12.rar.rar
共68个文件
class:10个
css:8个
map:8个
需积分: 5 1 下载量 175 浏览量
2022-10-30
17:40:49
上传
评论 1
收藏 758KB RAR 举报
温馨提示
project12.rar.rar
资源推荐
资源详情
资源评论
收起资源包目录
project12.rar.rar (68个子文件)
project12
pom.xml 642B
target
classes
com
zhy
servlet
CarServlet.class 3KB
QdServlet.class 2KB
BookServlet.class 2KB
entry
Car.class 466B
Book.class 922B
generated-sources
annotations
src
test
java
main
resources
java
com
zhy
servlet
BookServlet.java 1KB
QdServlet.java 1KB
CarServlet.java 2KB
entry
Car.java 223B
Book.java 551B
.idea
misc.xml 526B
jarRepositories.xml 864B
compiler.xml 542B
workspace.xml 12KB
.gitignore 218B
artifacts
project12_war_exploded.xml 511B
project12.iml 491B
out
artifacts
project12_war_exploded
img
book.jpg 18KB
META-INF
MANIFEST.MF 88B
WEB-INF
web.xml 402B
classes
com
zhy
servlet
CarServlet.class 3KB
QdServlet.class 2KB
BookServlet.class 2KB
entry
Car.class 466B
Book.class 922B
jsp
car.jsp 1KB
qiandao.jsp 484B
index.jsp 2KB
bootstrap-3.4.1-dist
jquery.js 88KB
bootstrap-3.4.1-dist
css
bootstrap-theme.css 25KB
bootstrap.css.map 382KB
bootstrap.min.css 119KB
bootstrap-theme.min.css.map 74KB
bootstrap.css 143KB
bootstrap-theme.min.css 23KB
bootstrap-theme.css.map 47KB
bootstrap.min.css.map 528KB
fonts
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.woff2 18KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.svg 106KB
js
npm.js 484B
bootstrap.min.js 39KB
bootstrap.js 74KB
web
img
book.jpg 18KB
WEB-INF
web.xml 402B
jsp
car.jsp 1KB
qiandao.jsp 484B
index.jsp 2KB
bootstrap-3.4.1-dist
jquery.js 88KB
bootstrap-3.4.1-dist
css
bootstrap-theme.css 25KB
bootstrap.css.map 382KB
bootstrap.min.css 119KB
bootstrap-theme.min.css.map 74KB
bootstrap.css 143KB
bootstrap-theme.min.css 23KB
bootstrap-theme.css.map 47KB
bootstrap.min.css.map 528KB
fonts
glyphicons-halflings-regular.woff 23KB
glyphicons-halflings-regular.woff2 18KB
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.svg 106KB
js
npm.js 484B
bootstrap.min.js 39KB
bootstrap.js 74KB
共 68 条
- 1
资源评论
理理滴滴答
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Picasso_v3.1 2.ipa
- chromedriver-mac-arm64.zip
- 蓝zapro.apk
- chromedriver-linux64.zip
- UCAS研一深度学习实验-MNIST手写数字识别python源码+详细注释(高分项目)
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- 基于SVM多特征融合的微表情识别python源码+项目说明+详细注释(高分课程设计)
- html动态爱心代码一(附源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功