BannerStudio---第四阶段考核项目(三)

简介: BannerStudio---第四阶段考核项目
7.DeleteShopCartServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShopCartService;
import org.lyl.taobao.service.ShopCartServiceImpl;
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 java.io.IOException;
/**
 * @Author: Re
 * @Date: 2021/4/8 17:09
 */
@WebServlet("/deleteShopCart")
public class DeleteShopCartServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer userId = Integer.parseInt(req.getParameter("userId"));
        Integer c_Id = Integer.parseInt(req.getParameter("c_Id"));
        IShopCartService iShopCartService = new ShopCartServiceImpl();
        if (iShopCartService.deleteShopCart(userId,c_Id)) {
            req.setAttribute("msg","删除成功");
        } else {
            req.setAttribute("msg","删除失败");
        }
        req.getRequestDispatcher("collect.jsp").forward(req,resp);
    }
}
8.ExitRegisterServlet
package org.lyl.taobao.controller;
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 javax.swing.text.html.HTML;
import java.io.IOException;
/**
 * @Author: Re
 * @Date: 2021/4/17 11:26
 */
@WebServlet("/exit")
public class ExitRegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        session.invalidate();
        req.getRequestDispatcher("registerUser.jsp").forward(req,resp);
    }
}
9.InsertUserServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 java.io.IOException;
/**
 * @Author: Re
 * @Date: 2021/3/26 19:24
 */
@WebServlet("/login")
public class InsertUserServlet extends HttpServlet {
    private static final Logger logger = LoggerFactory.getLogger(InsertUserServlet.class);
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String userPassword = req.getParameter("userPassword");
        if (userName == null || "".equals(userName.trim())){
            req.setAttribute("msg","用户名不能为空");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
            return;
        }
        if (userPassword == null || "".equals(userPassword)){
            req.setAttribute("msg","用户密码不能为空");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
            return;
        }
        User user = new User(userName,userPassword,0,"1");
        logger.info(user.toString());
        IUserService iUserService=new UserServiceImpl();
        if (iUserService.registerUser(user) != null) {
            req.setAttribute("msg","用户已存在");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
            return;
        }
        boolean judgment = iUserService.insertUser(user);
        if (judgment){
            req.setAttribute("msg",user);
            req.getRequestDispatcher("successUser.jsp").forward(req,resp);
        }else {
            req.setAttribute("msg","失败");
            req.getRequestDispatcher("login.jsp").forward(req,resp);
        }
    }
}
10.RegisterUserServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.ICommodityService;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.Commodity;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.CommodityServiceImpl;
import org.lyl.taobao.service.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.List;
/**
 * @Author: Re
 * @Date: 2021/3/29 20:41
 */
@WebServlet("/registerUser")
public class RegisterUserServlet extends HttpServlet {
    private static final Logger logger = LoggerFactory.getLogger(InsertUserServlet.class);
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            resp.setContentType("text/html;utf-8");
            String userName = req.getParameter("userName");
            String userPassword = req.getParameter("userPassword");
            String grade = req.getParameter("grade");
            if (userName==null || "".equals(userName)) {
                req.setAttribute("msg","用户名不能为空");
                req.getRequestDispatcher("registerUser.jsp").forward(req,resp);
                return;
            }
            if (userPassword==null || "".equals(userPassword)) {
                req.setAttribute("msg","密码不能为空");
                req.getRequestDispatcher("registerUser.jsp").forward(req,resp);
                return;
            }
            User user = new User(userName,userPassword,grade);
            logger.info(user.toString());
            IUserService iUserService=new UserServiceImpl();
            ICommodityService iCommodityService = new CommodityServiceImpl();
            User user1 = iUserService.registerUser(user);
            if (user1 != null) {
                HttpSession session = req.getSession();
                session.setAttribute("user",user1);
                Cookie cookie = new Cookie("JSESSIONID", session.getId());
                cookie.setPath(req.getContextPath()+"/");
                cookie.setMaxAge(30*60);
                resp.addCookie(cookie);
                if (grade.equals("1")) {
                    List<Commodity> commodityList = iCommodityService.checkAllCommodity();
                    HttpSession session1 = req.getSession();
                    session1.setAttribute("commodityListMsg",commodityList);
                    req.getRequestDispatcher("commoditys.jsp").forward(req,resp);
                } else if(grade.equals("2")){
                    req.getRequestDispatcher("checkUser.jsp").forward(req,resp);
                } else if(grade.equals("3")){
                    List<Commodity> list = iCommodityService.checkCommodityById(user1.getUserId());
                    req.setAttribute("list",list);
                    req.getRequestDispatcher("checkCommodity.jsp").forward(req,resp);
                }
            } else {
                req.setAttribute("msg","登录失败");
                req.getRequestDispatcher("registerUser.jsp").forward(req,resp);
            }
        }catch (Exception e) {
            e.printStackTrace();
            System.out.println("代码运行出错!!!");
        }
    }
}
11.UpdateCommodityServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.ICommodityService;
import org.lyl.taobao.service.CommodityServiceImpl;
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 java.io.IOException;
/**
 * @Author: Re
 * @Date: 2021/4/5 11:28
 */
@WebServlet("/updateCommodity")
public class UpdateCommodityServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;utf-8");
        req.setCharacterEncoding("UTF-8");
        String c_Id = req.getParameter("c_Id");
        String c_Name = req.getParameter("c_Name");
        String c_Price = req.getParameter("c_Price");
        int id = Integer.valueOf(c_Id);
        float price = Float.valueOf(c_Price);
        ICommodityService iCommodityService = new CommodityServiceImpl();
        if (iCommodityService.updateCommodity(id,c_Name,price)) {
            req.setAttribute("msg","更改成功");
        } else {
            req.setAttribute("msg","更改失败");
        }
        req.getRequestDispatcher("updateCommodity.jsp").forward(req,resp);
    }
}
12.UpdateUserServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
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;
/**
 * @Author: Re
 * @Date: 2021/4/1 21:21
 */
@WebServlet("/updateUser")
public class UpdateUserServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;utf-8");
        String updateUser = req.getParameter("updateUser");
        if (updateUser.equals("updateUser")) {
            req.getRequestDispatcher("updateUser.jsp").forward(req,resp);
        }else if (updateUser.equals("rightUpdate")){
            HttpSession session = req.getSession();
            User user = (User) session.getAttribute("user");
            String password1 = req.getParameter("password1");
            String password2 = req.getParameter("password2");
            if (!password1.equals(password2)){
                req.setAttribute("msg","两次输入密码不同,请重新输入");
                req.getRequestDispatcher("updateUser.jsp").forward(req,resp);
                return;
            } else {
                user.setUserPassword(password1);
                IUserService iUserService = new UserServiceImpl();
                if (iUserService.updateUser(user)){
                    req.setAttribute("msg","密码已修改");
                    req.getRequestDispatcher("registerUser.jsp").forward(req,resp);
                } else {
                    req.setAttribute("msg","密码更改失败");
                    req.getRequestDispatcher("registerUser.jsp").forward(req,resp);
                }
            }
        }
    }
}
13.UploadPicturesServlet
package org.lyl.taobao.controller;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
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.*;
import java.util.List;
import java.util.UUID;
/**
 * @Author: Re
 * @Date: 2021/4/12 22:19
 */
@WebServlet("/photo.do")
public class UploadPicturesServlet extends HttpServlet {
    private static final long serialVersionUID = 8525671995700987977L;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        if (!ServletFileUpload.isMultipartContent(req)){
            return;
        }
        String uploadPath  = this.getServletContext().getRealPath("/upload");
        System.out.println("this的值为-->"+this);
        System.out.println("文件保存路径-->" + uploadPath);
        File uploadFile = new File(uploadPath);
        // 文件夹要是不存在那就再建一个
        if (!uploadFile.exists()) {
            uploadFile.mkdir();
        }
        // 如果文件大小超出预期大小则存在临时路径
        String tempPath = this.getServletContext().getRealPath("/temp");
        System.out.println("临时文件保存路径-->" + tempPath);
        File tempFile = new File(tempPath);
        if (!tempFile.exists()) {
            tempFile.mkdir();
        }
        // 处理上传的文件,一般需要通过流来获取,我们可以使用request.getInputStream(),原生态的文件上传流获取,十分麻烦
        //但是我们都建议使用Apache的文件上传组件来实现,common-fileupload,他需要依赖commons-io组件
        // 1. 创建DiskFileItemFactory对象: 处理文件上传路径或者大小限制的
        DiskFileItemFactory factory = getDiskFileItemFactory(tempFile);
        /*
         * 2. 获取ServletFileUpload
         * ServletFileUpload负责处理上传的文件数据,并将表单中个每个输入项封装成一个FileItem对象
         * 在使用ServletFileUpload对象解析请求时需要DiskFileItemFactory对象
         * 所以,我们需要在进行解析工作前构造好DiskFileItemFactory对象
         * 通过ServletFileUpload对象的构造方法或setFileItemFactory()方法设置ServletFileUpload对象的fileItemFactory属性
         */
        ServletFileUpload upload = getServletFileUpload(factory);
        /*
         * 3.处理上传的文件
         */
        String msg = null;
        try {
            HttpSession session = req.getSession();
            User user = (User) session.getAttribute("user");
            msg = uploadParseRequest(upload,req,uploadPath);
            IUserService iUserService = new UserServiceImpl();
            iUserService.addPhoto(msg,user);
        } catch (FileUploadException e){
            e.printStackTrace();
        }
        // servlet请求转发消息
        req.setAttribute("msg",msg);
        req.getRequestDispatcher("homepage.jsp").forward(req,resp);
    }
    public static ServletFileUpload getServletFileUpload(DiskFileItemFactory factory){
        ServletFileUpload upload = new ServletFileUpload(factory);
        // 处理乱码
        upload.setHeaderEncoding("UTF-8");
        // 设置单个文件的最大值
        upload.setFileSizeMax(1024*1024*10);
        // 设置总共能够上传文件的大小
        upload.setSizeMax(1024*1024*10);
        return upload;
    }
    public static DiskFileItemFactory getDiskFileItemFactory(File file){
        // 通过该工厂设置一个缓冲区,当上传文件大于缓冲区时,将它放到临时文件中去
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // 设置缓冲区大小为10M
        factory.setSizeThreshold(1024*1024*10);
        // 临时目录的保存目录
        factory.setRepository(file);
        return factory;
    }
    public static String uploadParseRequest(ServletFileUpload upload,HttpServletRequest request,String uploadPath) throws FileUploadException,IOException{
        String msg = "";
        // 3.把前端请求解析,封装成一个FileItem对象
        List<FileItem> fileItems = upload.parseRequest(request);
        for (FileItem fileItem:fileItems) {
            // 判断上传的文件是普通的表单还是带文件的表单
            if (fileItem.isFormField()){
                // getFileName指的是前端表单控件的name
                String name = fileItem.getFieldName();
                // 处理乱码
                String value = fileItem.getString("UTf-8");
                System.out.println(name + ":" + value);
            } else {
                // 判断它是上传的文件
                //文件处理
                // 拿到文件名
                String uploadFileName = fileItem.getName();
                System.out.println("上传的文件名:" + uploadFileName);
                if ("".equals(uploadFileName.trim())||uploadFileName == null) {
                    continue;
                }
                // 获得上传文件名
                String fileName = uploadFileName.substring(uploadFileName.lastIndexOf("/")+1);
                // 获得文件后缀名
                String fileExtName = uploadFileName.substring(uploadFileName.lastIndexOf(".")+1);
                 /* 如果文件后缀名fileExtName不是我们需要的就直接return,不处理,并告诉用户文件类型不对
                 */
                System.out.println("文件信息[文件名:" + fileName + "--文件类型:" + fileExtName);
                 /*可以使用UUID(唯一识别通用码),保证文件名的唯一
                 * UUID.randomUUID(),随机生一个唯一识别的通用码
                 * 但是生成的UUID没有办法往数据库里存
                 */
                String uuidPath = UUID.randomUUID().toString();
                //文件处理完毕
                // 存到哪? uploadPath
                // 文件真实存放的路径 realPath
                String realPath = uploadPath + "/" +uuidPath;
                System.out.println(realPath);
                //给每个文件创建一个对应文件夹
                File realPathFile = new File(realPath);
                if (!realPathFile.exists()){
                    realPathFile.mkdir();
                }
                //存放地址完毕
                // 获得文件上传的流
                InputStream inputStream = fileItem.getInputStream();
                // 创建一个文件输出流
                // realPath = 真实的文件夹
                FileOutputStream fos = new FileOutputStream(realPath+"/"+fileName);
                // 创建一个缓冲区
                byte[] buffer = new byte[1024*1024];
                // 判断是否读取完毕
                int len = 0;
                while((len = inputStream.read(buffer)) > 0){
                    fos.write(buffer,0,len);
                }
                //关闭流
                fos.close();
                inputStream.close();
                msg = uuidPath + "/" + fileName;
                // 上传成功清除临时文件
                fileItem.delete();
            }
        }
        return msg;
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
  • jsp页面
    1.addCommodity.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>增加商品</title>
</head>
<body>
<div style="text-align: center;">
    <form action="/addCommodity" method="post">
        商品名:<input type="text" name="c_Name">
        价钱:<input type="text" name="c_Price">
        商品种类:<select name="c_Kind">
            <option value="clothing">服装</option>
            <option value="departmentStore">百货</option>
            <option value="food">食品</option>
            <option value="pet">宠物</option>
        </select>
        <button type="submit" name="userId" value="${user.userId}">提交</button><br>
        <span style="color: red;font-size: 15px">${msg}</span>
    </form>
</div>
</body>
</html>
2.checkCommodity.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>查看商品</title>
</head>
<body>
<form action="/checkCommodity" method="post">
    <table border="1">
        <tr>
            <th>商品名</th>
            <th>商品种类</th>
            <th>商品价格</th>
            <th>删除商品</th>
            <th>更改商品信息</th>
        </tr>
        <c:forEach items="${listMsg}" var="commodities">
            <tr>
                <td>${commodities.commodityName}</td>
                <td>${commodities.commodityKind}</td>
                <td>${commodities.commodityPrice}</td>
                <td><input type="checkbox" name="deleteCommodityById" value="${commodities.commodityId}"></td>
                <td><button type="submit" name="updateCommodityById" value="${commodities.commodityId}">更改</button></td>
            </tr>
        </c:forEach>
    </table>
    <button type="submit" name="check" value="deleteCommodity">删除商品</button>
    <button type="submit" name="check" value="addCommodity">添加商品</button>
    <button type="submit" name="userId" value="${user.userId}">查看商品信息</button><br>
    <span style="color: red;font-size: 15px">${msg}</span>
</form>
</body>
</html>
3.checkOrder.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>订单</title>
    <style>
        #PageBody {
            width: 37%;
            text-align: center;
        }
        .left {
            float: left;
            width: 17%;
        }
        .right {
            float: left;
            width: 30%;
        }
    </style>
</head>
<body>
<div id="PageBody">
    <form action="deleteOrder" method="post">
        <div class="right">
            <table style="border: 2px">
                <tr>
                    <th>商品名</th>
                    <th>价格</th>
                </tr>
                <c:forEach items="${commodityListMsg}" var="commodityList" begin="">
                <tr>
                    <td>${commodityList.commodityName}</td>
                    <td>${commodityList.commodityPrice}</td>
                <tr>
                    </c:forEach>
            </table>
        </div>
        <div class="left">
            <table>
                <tr>
                    <th>取消订单</th>
                </tr>
                <c:forEach items="${orderListMsg}" var="orderList">
                    <tr>
                    <td><button type="submit" name="cancel" value="${orderList.orderId}">取消订单</button> </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </form>
</div>
</body>
</html>
4.checkUser.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>查询所有的用户信息</title>
</head>
<body>
<div style="text-align: center">
    <form action="/checkUser" method="post">
        <div style="text-align: center">
        <table border="1">
            <tr>
                <th>用户ID</th>
                <th>用户名</th>
                <th>用户余额</th>
                <th>删除用户</th>
            </tr>
            <c:forEach items="${msg}" var="users">
                <tr>
                    <td>${users.userId}</td>
                    <td>${users.userName}</td>
                    <td>${users.balance}</td>
                    <td><input type="checkbox" name="deleteUserName" value="${users.userName}"></td>
                </tr>
            </c:forEach>
        </table>
        <button type="submit" name="check" value="deleteUser">删除用户</button>
        <button type="submit" name="check" value="allUsers">查看所有用户信息</button>
        <hr>
        查询用户的用户名<input type="text" name="checkUserName"  placeholder="用户名"><br>
        <button type="submit" name="check" value="user">查看个人信息</button><span style="color: red;font-size: 12px">${warning}</span>
        </div>
    </form>
    <h2>在线人数${onlineNumber}个</h2>
</div>
</body>
</html>
5.collect.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>购物车</title>
</head>
<body>
<div style="text-align: center">
    <form action="deleteShopCart" method="post">
        <input type="hidden" name="userId" value="${user.userId}">
    <table style="border: 2px">
        <tr>
            <th>商品名</th>
            <th>商品价格</th>
            <th>图片</th>
            <th>购买</th>
            <th>删除</th>
        </tr>
        <c:forEach items="${commoditiesMsg}" var="commodities">
            <tr>
                <td>${commodities.commodityName}</td>
                <td>${commodities.commodityPrice}</td>
                <td></td>
                <td style="text-align: center"><button type="submit" name="c_Id" value="${commodities.commodityId}">购买</button></td>
                <td style="text-align: center"><button type="submit" name="c_Id" value="${commodities.commodityId}">删除</button></td>
            </tr>
        </c:forEach>
    </table>
        <span style="color: red;font-size: 15px">${msg}</span>
    </form>
</div>
</body>
</html>
6.commoditys.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>主页</title>
</head>
<body>
<form action="addShopCart" method="post">
    <input type="hidden" name="userId" value="${user.userId}">
    <table border="1">
        <tr>
            <th>商品名</th>
            <th>商品价格</th>
            <th>加入购物车</th>
            <th>购买</th>
        </tr>
        <c:forEach items="${commodityListMsg}" var="commodity">
            <tr>
                <td>${commodity.commodityName}</td>
                <td>${commodity.commodityPrice}</td>
                <td><button type="submit" name="collect" value="${commodity.commodityId}">加入购物车</button></td>
                <td><button type="submit" name="buy" value="${commodity.commodityId}">购买</button> </td>
            </tr>
        </c:forEach>
    </table >
    <button type="submit" name="intoCollect" value="intoCollect">进入购物车</button>
    <button type="submit" name="intoOrder" value="intoOrder">进入订单页</button><br>
    <button type="submit" name="homepage" value="homepage">个人主页</button>
    <span style="color: red;font-size: 15px">${msg}</span>
</form>
</body>
</html>
7.homepage.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>个人主页</title>
</head>
<body>
<div style="background-color: lightgray">
    <h2>${user.userName}的个人主页</h2>
    <div style="display:block"><img style="height: 200px;width: 200px;background-color: aquamarine" src="upload/${user.img}"></div>
    <form action="photo.do" method="post" enctype="multipart/form-data">
        <input type="file" name="file">
        <input type="submit" value="提交">
    </form>
    <form action="exit" method="post">
        <button type="submit" name="exit" value="exit">退出登录</button>
    </form>
<%--    <form action="" method="post">
        <button type="submit" name="" value="">购物车</button>
        <button type="submit" name="" value="">订单</button>
    </form>--%>
</div>
</body>
</html>
8.index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<h2>主页</h2>
</body>
<div>
    <ul>
        <li>
            <a href="registerUser.jsp">请登录&nbsp</a><a href="login.jsp" class="style_red">免费注册</a>
        </li>
    </ul>
</div>
</form>
</html>
9.login.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>注册</title>
</head>
<body>
<div style="text-align: center">
    <form action="/login" method="post">
        用户名:<input type="text" name="userName"><br>
        密码:<input type="text" name="userPassword"><br>
        <button type="submit">提交</button> <span style="color: red;font-size: 12px">${msg}</span>
    </form>
</div>
</body>
</html>
10.registerUser.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<html>
<head>
    <title>登陆界面</title>
</head>
<body>
<div style="text-align: center;">
    <form action="/registerUser" method="post">
        用户名:<input type="text" name="userName"><br>
        用户密码:<input type="password" name="userPassword"><br>
        <input type="radio" name="grade" value="1" checked="checked" > 用户登录
        <input type="radio" name="grade" value="2">管理员登录
        <input type="radio" name="grade" value="3">商家登录
        <button type="submit">登录</button><br>
        <span style="color: red; font-size: 12px">${msg}</span>
    </form>
</div>
</body>
</html>
11.successUser.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>注册成功界面</title>
</head>
<body>
<div style="text-align: center;">
    <h2>欢迎${user.userName}登录</h2>
    用户基本信息如下:
    <table border="1">
        <tr>
            <td>用户姓名</td>
            <td>${user.userName}</td>
        </tr>
    </table>
    <form action="/updateUser" method="post">
        <button type="submit" name="updateUser" value="updateUser">更改用户信息</button>
    </form>
</div>
</body>
</html>
12.updateCommodity.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>更改商品信息</title>
</head>
<body>
<div style="text-align: center">
    <form action="/updateCommodity" method="post">
        商品名称更改为:<input type="text" name="c_Name"><br>
        商品价格更改为:<input type="text" name="c_Price"><br>
        <button type="submit" name="c_Id" value="${c_Id}">提交更改</button>
    </form><br>
    <span style="color: red;font-size: 12px;">${msg}</span>
</div>
</body>
</html>
13.updateUser.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>更改密码</title>
</head>
<body>
<form action="/updateUser" method="post">
    输入新密码: <input type="password" name="password1">
    确认新密码: <input type="password" name="password2">
    <button type="submit" name="updateUser" value="rightUpdate">确认更改</button>
</form>
<form action="/updateUser" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="提交">
</form>
<span style="color: red;font-size: 15px">${msg}</span>
</body>
</html>
14.uploadPictures.jsp
<%--
    Created by IntelliJ IDEA.
    User: Re
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>上传图片</title>
</head>
<body>
<form action="photo.do" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="提交">
</form>
</body>
</html>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <filter>
    <filter-name>DruidWebStatFilter</filter-name>
    <filter-class>com.alibaba.druid.support.http.WebStatFilter</filter-class>
    <init-param>
      <param-name>exclusions</param-name>
      <param-value>*. js ,*. gif ,*. jpg ,*. png ,*. css ,*. ico ,/ druid /*</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>DruidWebStatFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <servlet>
    <servlet-name>DruidStatView</servlet-name>
    <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>DruidStatView</servlet-name>
    <url-pattern>/druid/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.jpg</url-pattern>
  </servlet-mapping>
</web-app>

最后是我数据库里建的表

1.commodity

2.order

3.shopingcart

4.user

相关文章
|
9天前
|
数据可视化 项目管理
项目管理怎么做?四大项目管理模型详解,让你的项目不再“忙而无效”!
本文介绍四大经典项目管理模型:瀑布模型(适合需求明确的项目)、Scrum模型(适合需求频繁变化的项目)、增量模型(分阶段推进,逐步完成)和风险管理模型(防患于未然)。同时推荐几款常用工具,如板栗看板、Trello和Asana,帮助团队更高效地协作。
27 0
|
6月前
|
人工智能 安全 物联网
信息系统项目管理师重点内容汇总(第二天)
乘风破浪会有时,直挂云帆济沧海
254 1
|
6月前
|
存储 监控 搜索推荐
第十二章项目沟通管理和干系人管理(选择2分,偶尔案例20分)
第十二章项目沟通管理和干系人管理(选择2分,偶尔案例20分)
177 0
|
前端开发 Java API
BannerStudio---第四阶段考核项目(一)
BannerStudio---第四阶段考核项目
BannerStudio---第四阶段考核项目(一)
BannerStudio---BannerStudio20级第一阶段考核
BannerStudio---BannerStudio20级第一阶段考核
|
小程序 Java
如何用项目甘特图,做好项目汇报
如何用项目甘特图,做好项目汇报
|
数据采集 数据挖掘 项目管理
【PMP】十一、项目风险管理
【PMP】十一、项目风险管理
309 0
【PMP】十一、项目风险管理