基于javaweb的在线点餐+外卖配送系统

一、系统简介

本项目采用eclipse工具开发,jsp+servlet技术编写,样式采用了layui和bootstrap前段框架,数据库采用的是mysql,navicat开发工具。

系统一共分为4个角色分别是:管理员,普通用户,商家,外卖员

二、模块简介

管理员模块

1、登录

2、数据统计

3、用户管理

4、外卖员管理

5、餐品分类管理

6、商家管理

7、公告管理

8、评论管理

9、个人信息修改

商家模块

1、登录

2、个人信息修改

3、餐品管理

4、订单管理

5、数据统计

外卖员模块

1、登录

2、个人信息修改

3、订单配送

用户模块

1、登录注册

2、餐品浏览

3、加入购物车

4、收藏餐品

5、查看公告

6、下单餐品

7、个人信息修改

8、查看订单

9、收藏管理

三、页面截图

项目结构

 数据库页面

登录页面

 统计页面

 用户页面

 外卖员页面

 

 餐品分类页面

商家页面

公告页面 

 

 评论页面

 餐品页面

 订单页面

 前端首页

 餐品详情页面

 公告页面

 购物车页面

 收藏页面

 我的订单、

 个人信息修改

 四、相关代码

登录代码

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录</title>
    <link rel="icon" href="<%=path%>/resource/static/favicon.ico">
    <link rel="stylesheet" href="<%=path%>/resource/static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="<%=path%>/resource/static/admin/css/login.css">
    <script src="<%=path%>/resource/static/js/vue.min.js"></script>
    <script src="<%=path%>/resource/static/js/jquery-3.3.1.min.js"></script>
    <script src="<%=path%>/resource/static/bootstrap/js/bootstrap.bundle.js"></script>
</head>
<body>
<div class="login" style="height:430px;">
    <form id="saveForm">
        <h2>外卖配送系统</h2>
        <div class="form-group">
            <label>用户名</label>
            <input type="text" v-model="username" name="username" id="username" class="form-control form-control-lg">
        </div>
        <div class="form-group">
            <label>密码</label>
            <input type="password" v-model="password" name ="password" id="password" class="form-control form-control-lg" id="pwd">
        </div>
        <div class="form-group form-check">
           <input type="radio" class="form-check-input" name="type" value="1" id="exampleCheck2" checked>
            <label class="form-check-label" for="exampleCheck2">管理员</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
           <input type="radio" class="form-check-input" name="type" value="2" id="exampleCheck1" >
            <label class="form-check-label" for="exampleCheck1">用户</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             <input type="radio" class="form-check-input" name="type" value="3" id="exampleCheck1" >
            <label class="form-check-label" for="exampleCheck1">商家</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
             <input type="radio" class="form-check-input" name="type" value="4" id="exampleCheck1" >
            <label class="form-check-label" for="exampleCheck1">外卖员</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            
        </div> 
        <button type="button" :disabled="loading" @click="login" id="login" class="btn btn-primary btn-lg  btn-block">
            <span v-show="loading" class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
            立即登录
        </button>
       
    </form>
</div>

<script>
	    $("#login").click(function(){
	    	var username = $("#username").val();
	    	var password = $("#password").val();
	    	if(username == null || username == ""){
	    		alert("请填写用户名");
	    		return false;
	    	}if(password == null || password == ""){
	    		alert("请填写密码");
	    		return false;
	    	}
			//执行添加的操作ajax
			$.ajax({
				cache:true,
				type:"post",
				url:"LoginServlet?action=login",
				data:$("#saveForm").serialize(),
				async:false,
				success:function(e){//takeout
					if(e == 'ok'){
						alert("登录成功");
						 window.parent.location.href="LoginServlet?action=toMain";
					}else if(e == "user"){
                        alert("登录成功");
						 window.parent.location.href="IndexServlet?action=toIndex";
                    }else if(e == "merchant"){
                        alert("登录成功");
						 window.parent.location.href="LoginServlet?action=toMain";
                   }else if(e == "takeout"){
                       alert("登录成功");
						 window.parent.location.href="LoginServlet?action=toMain";
                    }else{
						alert("登录失败,账号或密码错误");
					}
				}
			})
		});
		   
</script>

</body>
</html>
/**
	 * 登录
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// 处理登录
		// 清空登录记录
		request.getSession().invalidate();
		// 进行登录操作
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String type = request.getParameter("type");
		if (type != null && type.equals("1")) {
			Admin admin1 = UserService.selectAdmin(username, password);
			if (admin1 != null) {
				response.getWriter().print("ok");
				request.getSession().setAttribute("admin", admin1);
				request.getSession().setAttribute("flag", 1);
			} else {
				response.getWriter().print("error");
			}
		} else if (type != null && type.equals("2")) {
			User User1 = UserService.selectUser(username, password);
			if (User1 != null) {
				response.getWriter().print("user");
				request.getSession().setAttribute("user", User1);
				request.getSession().setAttribute("flag", 2);
			} else {
				response.getWriter().print("error");
			}
		} else if (type != null && type.equals("3")) {
			Merchant data = MerchantService.selectMerchant(username, password);
			if (data != null) {
				response.getWriter().print("merchant");
				request.getSession().setAttribute("merchant", data);
				request.getSession().setAttribute("flag", 3);
			} else {
				response.getWriter().print("error");
			}
		} else if (type != null && type.equals("4")) {
			TakeOut data = TakeOutService.selectTakeOut(username, password);
			if (data != null) {
				response.getWriter().print("takeout");
				request.getSession().setAttribute("takeout", data);
				request.getSession().setAttribute("flag", 4);
			} else {
				response.getWriter().print("error");
			}
		} else {
			response.getWriter().print("error");
		}

	}

用户代码

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>用户列表</title>
<link rel="icon" href="<%=path%>/resource/static/favicon.ico">
<link rel="stylesheet"
	href="<%=path%>/resource/static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/index.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/main.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/html.css">
<script src="<%=path%>/resource/static/js/vue.min.js"></script>
<script src="<%=path%>/resource/static/js/jquery-3.3.1.min.js"></script>
<script src="<%=path%>/resource/static/bootstrap/js/bootstrap.bundle.js"></script>
<script src="<%=path%>/resource/static/admin/js/config.js"></script>
<script src="<%=path%>/resource/static/admin/js/script.js"></script>
<script>
	$(function() {
		const hrefArr = window.location.href.split('/');
		const name = hrefArr[hrefArr.length - 1];
		$('.menu a[href=\'' + name + '\']').addClass('active');
	});
</script>
<style>
	th,tr,td{    border: 1px solid #ced4da;}
</style>
</head>
<body>

	<div id="app" class="d-flex">
		<jsp:include page="/WEB-INF/common/line.jsp" />
		<main>
			<jsp:include page="/WEB-INF/common/head.jsp" />
			<div id="body">
				<main>
					<div class="main">
						<div class="search">
						<c:if test="${admin != null }">
						    <form class="form-inline float-left" action="UserServlet?action=UserList"
								method="post">
								<div class="form-group">
									<input type="text" name="key" value="${key}"
										class="form-control" placeholder="姓名">
								</div>
								<button type="submit" class="btn btn-primary">
									<i class="iconfont"></i>搜索
								</button>
							</form>
						</c:if>
							
						</div>

						<div >
							<table class="table">
								<thead>
									<tr>
										<th scope="col">姓名</th>
										<th scope="col">密码</th>
										<th scope="col">手机号</th>
										<th scope="col">性别</th>
										<th scope="col">注册时间</th>
										<th scope="col">头像</th>
										<th scope="col">操作</th>
									</tr>
								</thead>
								<tbody>

									<c:forEach items="${list}" var="data">
										<tr>
											<td>${data.realname }</td>
											<td>${data.pwd }</td>
											<td>${data.phone }</td>
											<td>${data.sex }</td>
											<td>${data.times }</td>
									       <td><img src="/images/${data.img}"  style="width:50px; height:50px; "></td>	
											
                                      <td>
											<input id ="${data.id}" value="${data.id}" type="hidden" class="weui-input"/>
											<a class="btn btn-primary btn-sm"
												href="UserServlet?action=toUpdateUser&id=${data.id }">修改</a> 
												<c:if test="${admin != null }">
												<a  class="btn btn-danger btn-sm delete"
												href="javascript:;">删除</a>
												</c:if>
												</td>
										</tr>
									</c:forEach>

								</tbody>
							</table>
						</div>

						<div class="page">
							<ul class="pagination">
								<li class="page-item"><a class="page-link"
									href="UserServlet?action=UserList&p=1">首页</a></li>
								<c:if test="${cp>1}">
									<li class="page-item"><a class="page-link"
															 href="UserServlet?action=UserList&p=${cp-1}">上一页</a></li>
								</c:if>
								<c:forEach begin="${cp-2>1 ? (cp-2) :1}"
										   end="${cp+2>tp?tp:(cp+2)}" var="e">
									<%--            判断是否是当前页--%>
									<c:if test="${cp==e}">
										<li class="page-item"><a class="page-link" style="background-color: #007bff;color:white"
																 href="UserServlet?action=UserList&p=${e}">${e}</a></li>
									</c:if>
									<c:if test="${cp!=e}">
										<li class="page-item"><a class="page-link"
																 href="UserServlet?action=UserList&p=${e}">${e}</a></li>
									</c:if>
								</c:forEach>
								<c:if test="${cp<tp}">
									<li class="page-item"><a class="page-link"
															 href="UserServlet?action=UserList&p=${cp+1}">下一页</a></li>
								</c:if>
								<li class="page-item"><a class="page-link"
														 href="UserServlet?action=UserList&p=${tp}">尾页</a></li>
							</ul>

						</div>
					</div>
				</main>
			</div>

		</main>
	</div>
	<script>
	
	   $('a.delete').click(function(e) 
   		        {
   		            var id = $(e.currentTarget).parent().find('.weui-input').attr('id');
			   		if(confirm("确定删除吗?")){
			 		   $.ajax({
						    cache:true,
							url:"UserServlet?action=deleteUser",
						  	data:{"id": id},
							type:"post",
						    async:false,
						  	success:function (data) {
								console.log(data)
							 	if (data == 'yes') {
									alert("删除成功!");
									document.location.reload();//当前页面
							  	}else{
							  		alert("删除失败!");
							  	}
						 	}  
					 	}); 
			 		}

   		        })
	
	</script>
</body>
</html>

	/**
	 * 用户列表
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void UserList(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {// 跳转到社长列表界面
		String p = request.getParameter("p");// 接收页码
		String key = request.getParameter("key");// 接收页码
		User User = (User)request.getSession().getAttribute("User");
		System.out.print(p);
		int pageSize = 6;// 每页显示5条
		int pageNum = 1; // 默认第一页
		if (p != null) {
			pageNum = Integer.parseInt(p);
		}
		Map map = new HashMap<>();
		map.put("key", key);
		map.put("uid", User!=null?User.getId():null);
		// 调用分页查询
		List<User> list = UserService.getUserPage(pageNum, pageSize, map);
		// 携带参数到页面
		request.setAttribute("list", list); // 绑定参数
		int nums = UserService.queryUserCount(map); // 查询总数
		// 计算总页数
		int totalPage = (nums % pageSize == 0) ? (nums / pageSize) : (nums / pageSize + 1);
		request.setAttribute("cp", pageNum); // 当前页
		request.setAttribute("tp", totalPage); // 总页数
		request.setAttribute("key", key); // 总页数
		// 条件 值1:值2
		request.getRequestDispatcher("/WEB-INF/view/user/list.jsp").forward(request, response); // 页面转发
	}
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, User-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>添加用户</title>
<link rel="icon" href="<%=path%>/resource/static/favicon.ico">
<link rel="stylesheet"
	href="<%=path%>/resource/static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/index.css">
<link rel="stylesheet"
	href="<%=path%>/resource/layui/css/layui.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/main.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/html.css">
<script src="<%=path%>/resource/static/js/vue.min.js"></script>
<script src="<%=path%>/resource/static/js/jquery-3.3.1.min.js"></script>
<script src="<%=path%>/resource/static/bootstrap/js/bootstrap.bundle.js"></script>
<script src="<%=path%>/resource/static/admin/js/config.js"></script>
<script src="<%=path%>/resource/static/admin/js/script.js"></script>
<script src="<%=path%>/resource/layui/layui.js"></script>
<script  type="text/javascript" src="<%=path%>/resource/My97DatePicker/WdatePicker.js"></script>
<style>
iframe {
 width: 218px !important;
    height: 350px !important;
    position: absolute;
    z-index: 117;
    top: -97px !important;
    right: -500px !important;
    width: 100%;
    height: 100%;
    border: 0;
    padding-top: 60px;
}
</style>
<script>
	$(function() {
		const hrefArr = window.location.href.split('/');
		const name = hrefArr[hrefArr.length - 1];
		$('.menu a[href=\'' + name + '\']').addClass('active');
	});
</script>
</head>
<body>

	<div id="app" class="d-flex">
		<jsp:include page="/WEB-INF/common/line.jsp" />

		<main>
			<jsp:include page="/WEB-INF/common/head.jsp" />

			<div id="body">
				<main>
					<div class="main">

						<div class="title-box">
							<h5>新增用户</h5>
						</div>
						<div >
							<div class="row">
								<div class="col-5">
									<form id="saveForm" enctype="multipart/form-data" >


										<div class="form-group">
											<label>姓名</label> <input type="text" name="realname"
												class="form-control"> <small
												class="form-text text-muted"></small>
										</div>

										<div class="form-group">
											<label>密码</label> <input type="text" name="pwd"
												class="form-control"> <small
												class="form-text text-muted"></small>
										</div>

										<div class="form-group">
											<label>手机号</label> <input type="text" name="phone"
												class="form-control"> <small
												class="form-text text-muted"></small>
										</div>

										<div class="form-group">
											<label>性别</label> <select name="sex" class="form-control">
											<option value="男">男</option>
											<option value="女">女</option>
										</select> <small class="form-text text-muted"></small>
										</div>
										
										<div class="form-group">
											   <label>头像</label>
											   <img class="layui-upload-img" style="width:200px;height:100px;" id="demo1">
											  <input type="file" name="img" id="img" >
											   <small class="form-text text-muted"></small>
										    </div>
									</form>
								</div>
							</div>

						</div>


						<div class="submit-box">
							<button type="button" id="save" class="btn btn-primary">确定提交</button>
							<!--             <button type="button" onclick="window.history.back()" class="btn btn-outline-secondary">取消</button>
 -->
						</div>
					</div>
				</main>



			</div>

		</main>
	</div>
	<script>
		$("#save").click(function() {
			$.ajax({
				cache:true,
				type : "post",
				url : "UserServlet?action=addUser",
				//data : $("#saveForm").serialize(),
				data : new FormData($('#saveForm')[0]),
				processData: false,
				contentType: false,
				async:false,
				success : function(e) {
					if (e == "yes") {
						alert("新增成功!");
						window.parent.location.href = "UserServlet?action=UserList";
					} else if (e == "isExist") {
						alert("新增失败,学号重复");
					}else{
						alert("新增失败");
					}
				}
			})
		});
	</script>
	
	
<script>

layui.use([ 'form','jquery','layer','laydate','upload' ], function() {
	var form = layui.form,
	 layer = layui.layer,
	 laydate = layui.laydate,
	 upload = layui.upload,
	 $= layui.jquery;
	 form.render();//这句一定要加,占坑
	
	  /*   laydate.render({
	    elem: '#schoolTime'
	  }); 
	    laydate.render({
	    elem: '#day'
	  });  */

	$("#img").change(function () {
		//创建blob对象,浏览器将文件放入内存中,并生成标识
		var img_src = URL.createObjectURL($(this)[0].files[0]);
		//给img标检的src赋值
		document.getElementById("demo1").src=img_src;
		//URL.revokeObjectURL(img_src);// 手动 回收,
	});
	  
	  });


</script>
	

</body>
</html>
/**
	 * 添加用户
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void addUser(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {// 处理注册
		String message = "no";
	//	User User = WebUtils.toBean(request.getParameterMap(), User.class);
		User User = fileUpload(request);
		User Users = UserService.selectUserByKey(User.getPhone());
		if (Users == null) {
			User.setTimes(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
			UserService.addUser(User);
			message = "yes";
		} else {
			message = "isExist";
		}
		response.getWriter().print(message);

	}
	
	/**
	 * 上传文件工具方法
	 * 
	 * @param request
	 * @return
	 */
	private User fileUpload(HttpServletRequest request) {
		User User = new User();
		try {
			DiskFileItemFactory factory = new DiskFileItemFactory();
			ServletFileUpload upload = new ServletFileUpload(factory);
			List<FileItem> list = upload.parseRequest(request);
			for (FileItem item : list) {
				if (item.isFormField()) {
					String name = item.getFieldName();
					String value = item.getString("UTF-8");
					BeanUtils.setProperty(User, name, value);
				} else {
					String name = item.getFieldName();
					
					String filename = item.getName();
					if(filename != null && !filename.equals("")) {
						String savefilename = makeFileName(filename);
						String savepath = "D:\\upload\\";
						InputStream in = item.getInputStream();
						FileOutputStream out = new FileOutputStream(savepath + "\\" + savefilename);
						int len = 0;
						byte buffer[] = new byte[1024];
						while ((len = in.read(buffer)) > 0) {
							out.write(buffer, 0, len);
						}
						in.close();
						out.close();
						item.delete();
						User.setImg(savefilename);
					}
				}
			}
			return User;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	private String makeFileName(String filename) {
		String ext = filename.substring(filename.lastIndexOf(".") + 1);
		return UUID.randomUUID().toString() + "." + ext;
	}
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, data-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>添加用户</title>
<link rel="icon" href="<%=path%>/resource/static/favicon.ico">
<link rel="stylesheet"
	href="<%=path%>/resource/static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/index.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/main.css">
<link rel="stylesheet"
	href="<%=path%>/layui/css/layui.css">
<link rel="stylesheet"
	href="<%=path%>/resource/static/admin/css/html.css">
<script src="<%=path%>/resource/static/js/vue.min.js"></script>
<script src="<%=path%>/resource/static/js/jquery-3.3.1.min.js"></script>
<script src="<%=path%>/resource/static/bootstrap/js/bootstrap.bundle.js"></script>
<script src="<%=path%>/resource/static/admin/js/config.js"></script>
<script src="<%=path%>/resource/static/admin/js/script.js"></script>
<script src="<%=path%>/resource/layui/layui.js"></script>
<script  type="text/javascript" src="<%=path%>/resource/My97DatePicker/WdatePicker.js"></script>
<style>
iframe {
 width: 218px !important;
    height: 350px !important;
    position: absolute;
    z-index: 117;
    top: -97px !important;
    right: -500px !important;
    width: 100%;
    height: 100%;
    border: 0;
    padding-top: 60px;
}
</style>
<script>
	$(function() {
		const hrefArr = window.location.href.split('/');
		const name = hrefArr[hrefArr.length - 1];
		$('.menu a[href=\'' + name + '\']').addClass('active');
	});
</script>
</head>
<body>

	<div id="app" class="d-flex">
		<jsp:include page="/WEB-INF/common/line.jsp" />

		<main>
			<jsp:include page="/WEB-INF/common/head.jsp" />

			<div id="body">


				<main>
					<div class="main">

						<div class="title-box">
							<h5>修改用户</h5>
						</div>
						<div >
							<div class="row">
								<div class="col-5">
									<form id="saveForm" enctype="multipart/form-data" >
									<input type="hidden" name="id" value="${data.id }">
									<input type="hidden" name="img" value="${data.img }">


										<div class="form-group">
											<label>姓名</label> <input type="text" name="realname" value="${data.realname }"
												class="form-control"> <small
												class="form-text text-muted"></small>
										</div>

										<div class="form-group">
											<label>密码</label> <input type="text" name="pwd" value="${data.pwd }"
												class="form-control"> <small
												class="form-text text-muted"></small>
										</div>

										<div class="form-group">
											<label>手机号</label> <input type="text" name="phone" value="${data.phone }"
												class="form-control"> <small
												class="form-text text-muted"></small>
										</div>

										<div class="form-group">
											<label>性别</label> <select name="sex" class="form-control">
											<option value="男" <c:if test="${data.sex == '男'}">selected</c:if> >男</option>
											<option value="女" <c:if test="${data.sex == '女'}">selected</c:if> >女</option>
										</select> <small class="form-text text-muted"></small>
										</div>
										
										
											<div class="form-group">
											   <label>头像</label>
											   <img class="layui-upload-img"  src="/images/${data.img }" style="width:200px;height:100px;" id="demo1">
											  <input type="file" name="img" id="img" >
											   <small class="form-text text-muted"></small>
										    </div>
									
										
									</form>
								</div>
							</div>
						</div>

						<div class="submit-box">
							<button type="button" id="save" class="btn btn-primary">确定提交</button>
							<a type="button" href="UserServlet?action=UserList" class="btn btn-outline-secondary">返回</a>
						</div>
					</div>
				</main>
			</div>
		</main>
	</div>
	<script>
		$("#save").click(function() {
			$.ajax({
				cache : true,
				type : "post",
				url : "UserServlet?action=updateUser",
				data : new FormData($('#saveForm')[0]),
				processData: false,
				contentType: false,
				//data : $("#saveForm").serialize(),
				async : false,
				success : function(e) {
					if (e == 'yes') {
						alert("修改成功!");
						window.parent.location.href = "UserServlet?action=UserList";
					} else {
						alert("修改失败!");
					}
				}
			})
		});
	</script>
	
		
<script>

layui.use([ 'form','jquery','layer','laydate','upload' ], function() {
	var form = layui.form,
	 layer = layui.layer,
	 laydate = layui.laydate,
	 upload = layui.upload,
	 $= layui.jquery;
	 form.render();//这句一定要加,占坑
	
	  /*   laydate.render({
	    elem: '#schoolTime'
	  }); 
	    laydate.render({
	    elem: '#day'
	  });  */
	  
		$("#img").change(function () {
			//创建blob对象,浏览器将文件放入内存中,并生成标识
			var img_src = URL.createObjectURL($(this)[0].files[0]);
			//给img标检的src赋值
			document.getElementById("demo1").src=img_src;
			//URL.revokeObjectURL(img_src);// 手动 回收,
		});
		  
	 
	    

	  });


</script>
</body>
</html>
	/**
	 * 修改用户
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void updateUser(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {// 查询个人信息
		String message = "no";
		//User User = WebUtils.toBean(request.getParameterMap(), User.class);
		User User = fileUpload(request);
		UserService.updateUser(User);
		message = "yes";
		response.getWriter().print(message);

	}

其他模块代码都非常类似,简易好懂!!!!

该项目整体比较简单,适合初学者学习!!!!

喜欢的点赞加关注,有兴趣的话,可以相互交流交流!!!!

项目截图中的数据,很多是用来测试的,需要自行添加合适的数据图片!!

获取地址https://www.jiuniao.com/code/13489.html 

评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码盗_java_bishe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值