JSP 购物车作品
用数据库方式存储数据,完成以下内容,作品名称:购物车(1)实现5个网页,如下:a.前台“选择商品”(GoodsCar.jsp)b.后台“选择商品并处理”(addinto....
用数据库方式存储数据,完成以下内容,作品名称:购物车 (1)实现5个网页,如下:a.前台“选择商品” (GoodsCar.jsp) b.后台“选择商品并处理” (addinto.jsp) c.前台“选择要删除的商品” (selectRemovedGoods.jsp)d.后台“处理和删除商品”(removeWork.jsp)e.后台“结帐”(count.jsp):每样商品金额小计,和总金额计算。 (2)前4个网页的具体布局和效果图由同学们自己设计并完成。但还有如下要求:I.数据存放在数据库中,每个网页都需要用表格显示出用户动态购买情况表。表格共5列:商品名、数量、单位、单价、金额。II. 第一个网页必须包含有“商品名称”,“数量”,“单位”,“单价”的表单控件,供用户选择或输入,进行商品购买。第三个网页只包含有“商品名称”控件,供用户选择删除的商品。III.5个网页的每个网页都有去到第一个网页(购买网页)和第三个网页(删除已选择购买的商品)的按钮。IV.前4个网页的每个页面应有“去结帐”按钮,转向“结帐”网页。(3)在“结帐”网页中实现计算商品单项金额和总金额的功能,具体页面由同学自己设计。要求效果类似于大型超市的购物小票。请打包发到332621651上面 感激不尽啊!!
展开
1个回答
2013-11-02
展开全部
把核心代码给你 其他你自己弄吧 类一为创建购物车 类二为显示购物车类一:
public class MyShopCar extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int id=Integer.parseInt(request.getParameter("proID"));
HttpSession session=request.getSession();
HashMap cars=(HashMap)session.getAttribute("cars"); 类二:public class ShowCarServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List list=new ArrayList();
ProductDao proDao=new ProductDao();
HttpSession session=request.getSession();
HashMap map=(HashMap)session.getAttribute("cars");
Iterator ator=map.keySet().iterator();
int sums=0;
while(ator.hasNext())
{
Integer id=(Integer)ator.next();
Integer count=(Integer)map.get(id);
Product pro=proDao.getAllById(id);
pro.setCount(count);
sums+=pro.getSum();
list.add(pro);
}
request.setAttribute("list", list);
request.setAttribute("sums", sums+"");
request.getRequestDispatcher("myShopCar.jsp").forward(request, response); }}
if(cars==null)
{
cars=new HashMap();
}
Integer count = (Integer)cars.get(id);
if(count==null)
{
cars.put(id, 1);
}else
{
cars.put(id, count+1);
}
session.setAttribute("cars", cars);
response.sendRedirect("ShowCarServlet");
}}
public class MyShopCar extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
int id=Integer.parseInt(request.getParameter("proID"));
HttpSession session=request.getSession();
HashMap cars=(HashMap)session.getAttribute("cars"); 类二:public class ShowCarServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List list=new ArrayList();
ProductDao proDao=new ProductDao();
HttpSession session=request.getSession();
HashMap map=(HashMap)session.getAttribute("cars");
Iterator ator=map.keySet().iterator();
int sums=0;
while(ator.hasNext())
{
Integer id=(Integer)ator.next();
Integer count=(Integer)map.get(id);
Product pro=proDao.getAllById(id);
pro.setCount(count);
sums+=pro.getSum();
list.add(pro);
}
request.setAttribute("list", list);
request.setAttribute("sums", sums+"");
request.getRequestDispatcher("myShopCar.jsp").forward(request, response); }}
if(cars==null)
{
cars=new HashMap();
}
Integer count = (Integer)cars.get(id);
if(count==null)
{
cars.put(id, 1);
}else
{
cars.put(id, count+1);
}
session.setAttribute("cars", cars);
response.sendRedirect("ShowCarServlet");
}}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询