MVC购物车案例

本文介绍了使用MVC模式开发的购物车系统,包括数据库设计、entity包的构建、用户界面(jsp)的设计如登录、注册、商品展示、购物车、订单及详情等,以及控制器(servlet)的数据处理功能,如登录注册、商品绑定、购物车操作和订单管理等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MVC购物车

定义

  • MVC本来是存在于Desktop程序中的,M是指数据模型(entity),V是指用户界面(jsp),C则是控制器(servlet)。

数据库设计

entity包

在这里插入图片描述

用户界面(jsp)

在这里插入图片描述

登录界面

<%@page import="com.zking.entity.Users"%>
<%-- <%@page import="com.zking.dao.UserDao"%> --%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户登录</title>
<link href="<%=request.getContextPath()%>/static/images/login.css" rel="stylesheet" type="text/css" />
<style type="">
	/* #top_center {
    width: 248px;
    height: 89px;
    background: url(UserLogin.png);
    float: left; */
}
</style>
</head>
<body onload = "yzm()">
    <div id="login">
	
	     <div id="top">
		      <div id="top_left"><img src="<%=request.getContextPath() %>/static/images/login_03.gif" /></div>
			  <div id="top_center"></div>
		 </div>
		<form action="<%=request.getContextPath() %>/LoginServlet.do" method="post" >
			<div id="center">
					      <div id="center_left"></div>
						  <div id="center_middle" style="height:235px;">
						       <div id="user">用 户
						         <input type="text" name="uname"  id = "uname" />
						       </div>
							   <div id="password">密   码
							     <input type="password" name="upwd"  id = "upwd" />
							   </div>
							   <!-- 验证码 -->
							   <div  id="yzm" style="margin-top: 10px; margin-left: 37px;padding-top:10px ">
									验证码 <input type="text" name="uyzm" style="width: 60px; "onkeydown = "checkUyzm()" />
									<span ><font size="" color="palevioletred" id="syzm"></font></span>
								</div>
							   <div id="btn">
							   		<button type="submit" style="display: block;line-height: 25px;background: url(bt_bg.gif);
			border: solid 1px #b6b6b6;
			    width: 65px;
			    float: left;
			    margin-left: 15px;
			    text-decoration: none;
			    color: #000;">登录</button>
									<button type="button" style="display: block;
			    line-height: 25px;
			    background: url(bt_bg.gif);
			    border: solid 1px #b6b6b6;
			    width: 65px;
			    float: left;
			    margin-left: 15px;
			    text-decoration: none;
			    color: #000;">清空</button>
							   </div>
						  
						  </div>
						  <div id="center_right" ></div>		 
					 </div>
		</form>
		 
		 <div id="down">
		      <div id="down_left">
			      <div id="inf">
                       <span class="inf_text">版本信息</span>
					   <span class="copyright">管理信息系统 2008 v2.0</span>
			      </div>
			  </div>
			  <div id="down_center"></div>		 
		 </div>

	</div>
	
</body>

<script type="text/javascript" src="<%=request.getContextPath() %>/static/js/loginCheck.js"></script>
</html>
    

注册界面

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>注册 </title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  
    <!-- Custom Theme files -->
    <link rel="stylesheet" type="text/css" href="https://www.jq22.com/jquery/font-awesome.4.6.0.css">
    <link href="${pageContext.request.contextPath}/static/css/snow.css" rel="stylesheet" type="text/css" media="all" />
    <link href="${pageContext.request.contextPath}/static/css/style.css" rel="stylesheet" type="text/css" media="all" />

</head>
<body>
    <div class="snow-container">
        <div class="snow foreground"></div>
        <div class="snow foreground layered"></div>
        <div class="snow middleground"></div>
        <div class="snow middleground layered"></div>
        <div class="snow background"></div>
        <div class="snow background layered"></div>
    </div>

    <div class="top-buttons-agileinfo">
        <a href="${pageContext.request.contextPath}/admin/login.jsp">Sign In</a><a href="${pageContext.request.contextPath}/home/signup.jsp" class="active">Sign Up</a>
    </div>
    <h1>注册</h1>
    <div class="main-agileits">
        <!--form-stars-here-->
        <div class="form-w3-agile">
            <h2 class="sub-agileits-w3layouts">注册</h2>
            <form action="${pageContext.request.contextPath}/SignupServlet.do" method="post">
                <input type="text" name="uname" value="   " placeholder="Username" required="" />
                <input type="password" name="upwd" placeholder="Password" required="" />
                <div class="submit-w3l">
                    <input type="submit" value="注册">
                </div>
            </form>
        </div>
    </div>
    <!--//form-ends-here-->
    <!-- copyright -->
    <div class="copyright w3-agile">
        <p> © 2019 带下雪背景的登录注册页面 . All rights reserved | Design by <a href="#">Reserved</a></p>
    </div>
    <!-- //copyright -->
    <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>

</body>
</html>

商品界面

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="com.zking.entity.Goods"%>
<%@page import="com.zking.biz.impl.GoodsBiz"%>
<%@page import="com.zking.biz.IGoodsBiz"%>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>商品</title>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

<%--    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->--%>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
  </head>
  
  <!-- 判断集合里面有没有数据,没有数据调到数据处理界面 -->
  <c:if test="${empty listGoods}">
  	<jsp:forward page="/LoadIndexServlet.do"></jsp:forward>
  </c:if>
  
  <body>
  <div class="container">
      <h3 style="text-align: center">商城列表</h3>
      <form action="">
      	<input type="text" contenteditable="true"/>
      	<button class="btn btn-primary">查询</button>
      </form>
      <table border="1" class="table table-bordered table-hover" style ="text-align: center;">
          <tr class="success">
              <th>商品序号</th>
              <th>商品名称</th>
              <th>商品价格</th>
              <th>商品描述</th>
              <th>商品图片</th>
               <th>商品数量</th>
              <th>操作</th>
          </tr>
        <c:forEach var="g" items="${listGoods }">
        	<tr>
              <td>${
   g.gid }</td>
              <td>${
   g.gname}</td>
              <td>${
   g.gprice }</td>
              <td>${
   g.ginfo }</td>
              <td><img src="${pageContext.request.contextPath}/static/${g.gpath }"></td>
              <td><a class="btn btn-default btn-sm" href="cart.jsp">购买</a>&nbsp;</td>
               
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值