[JAVAWEB development] Design and implementation of online shopping system based on Java+Servlet+Ajax+jsp

Hello~ Hello everyone, this article brings you the design of the online shopping system. In the era of traditional e-commerce, users first need to buy before purchasing, users are more dependent on the platform, and it is difficult for merchants to have direct influence on consumers, but now social + e-commerce solves the problem of information asymmetry in product quality, e-commerce It has become an important area of ​​today's economic development. And online shopping is one of the realizations, and now let's take a look.

1. Effect demonstration

1. Home page interface

 If you are not logged in, you can only view and cannot purchase

2. Product interface

 3. Product details interface

 4. Shopping cart interface

 5. Shopping order interface

 

 6. Successful transaction interface

 7. Personal order interface

8. Personal collection interface

 9. Administrator interface

 10. All order interface

 11. All Favorites interface

 Second, the database design

Database Definition: A database is a warehouse that stores data. It has a large storage space and can store millions, tens of millions, and hundreds of millions of data. However, the database does not store data at will, there are certain rules, otherwise the query efficiency will be very low. Today's world is an internet world full of data, full of massive amounts of data. That is, the Internet world is the data world. There are many sources of data, such as travel records, consumption records, web pages browsed, messages sent, and so on. In addition to text-type data, images, music, and sounds are all data.

User table (user) : fields (id, username, password, phone, email)

Shopping cart table (shopping_cart): fields (id, user name, commodity name, price, purchase quantity, total price, image address)

Order table (order): fields (id, commodity name, email, user name, delivery address, delivery phone)

Product details table (goods_parameters): fields (id, product type, image address)

Product type (favorite): field (id, product type name)

Commodity table (user): fields (id, commodity name, commodity type name, price, image address, sales, inventory)

Favorite table (favorite): fields (id, user name, product name, price, picture address)

History table (browsinghistory): fields (id, record name, record price, record picture address),

Brand table (brand) : fields (id, username, brand type, brand name)

3. Partial code display

Login Show

    <div class="registerarea ">
        <!-- 注册表头部 -->
        <h4>登录账号
            <div class="login"> 没有账号,去<a href="register.jsp" class="style_red">注册</a> &nbsp;&nbsp; <a href="retrievePassword.jsp">忘记密码?点击找回</a></div>
        </h4>
        <!-- 注册表身体 -->
        <div class="reg_form">
            <form action="/EasybuyProject/loginServlet" class="submit" method="post">
                <ul class="clearfix:after">
                    <li>
                        <label>账号:</label> <input type="text" class="inp username" name="username">
                        <span class="error">格式错误,应为长度6-20并含有大小写字母数字</span>
                        <font color="red">
                            <%
                                if(session.getAttribute("messageLogin")!= null){
                                    out.print(session.getAttribute("messageLogin"));
                                    session.invalidate();
                                }
                            %>
                        </font>


                    </li>

                    <li>
                        <label>密码:</label> <input type="password" class="inp password" name="password">
<%--                        <span class="error">格式错误,应为长度6-20并含有大小写字母数字</span>--%>
                    </li>
                    <li>
                        <input type="submit" class="inputButton" value="登录"> &nbsp;&nbsp;
                        <input type="reset" value="重置" class="inputButton">
                    </li>
                </ul>
            </form>
        </div>
    </div>

Regular verification

    <script>
        $(document).ready(function () {
            $(function () {
                var flagUser = false
                var flagPwd = false

                var $user_name = $('.username')
                var $pwd = $('.password')

                $user_name.blur(function () {
                    var vals = $user_name.val();
                    var reg = /^[a-zA-Z0-9\_]{6,20}$/;
                    if (reg.test(vals)) {
                        $user_name.next().hide();
                        flagUser = true;
                    } else {
                        // $user_name.next().show().css("z-index","2").html('用户名是6-20位数字、字母和下划线!');
                        $user_name.next().show();
                        flagUser = false;
                    }
                })

                $pwd.blur(function () {
                    var vals = $pwd.val();
                    var reg = /^[a-zA-Z0-9\_]{6,20}$/;

                    if (reg.test(vals)) {
                        $pwd.next().hide();
                        flagPwd = true;
                    } else {
                        $pwd.next().show();
                        flagPwd = false;
                    }
                })

            })
        })
    </script>

Servlet

@WebServlet("/EasybuyProject/loginServlet")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf8");
        resp.setCharacterEncoding("utf8");
        resp.setContentType("text/html;charset=UTF-8");

        String username = req.getParameter("username");
        String password = req.getParameter("password");

        UserService userService = new UserServiceImpl();
        User user = userService.login(username, password);

        HttpSession session = req.getSession();

        if (user != null && (!Objects.equals(username, "XzwadminNo1")) && !Objects.equals(password, "XzwadminNo1")) {
            resp.sendRedirect("/FrontPage/index.jsp");
            session.setAttribute("success",username);
        } else if(Objects.equals(username, "XzwadminNo1") && Objects.equals(password, "XzwadminNo1")){
            session.setAttribute("success",username);
            resp.sendRedirect("/FrontPage/indexAdmin.jsp");
        } else {
            session.setAttribute("messageLogin","用户名或者密码错误");
            resp.sendRedirect("/FrontPage/login.jsp");
        }

    }

}

entity class

public class User {

    private int id;
    private String username;
    private String password;
    private String tel;
    private String email;

    public User() {
    }

    public User(String tel, String email) {
        this.tel = tel;
        this.email = email;
    }

    public User(int id, String username, String password, String tel, String email) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.tel = tel;
        this.email = email;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", tel='" + tel + '\'' +
                ", email='" + email + '\'' +
                '}';
    }
}

Dao

    public User login(String username, String password) {
        User user = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            connection = JdbcUtil.getConnection();
            String sql = "select * from user where username = ? and password= ?";
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, password);

            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                user = new User();
                user.setUsername(resultSet.getString("username"));
                user.setPassword(resultSet.getString("password"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JdbcUtil.release(resultSet, preparedStatement, connection);
        }
        return user;
    }

Show results

See the official account for source code acquisition

If you don’t accumulate a few steps, you can’t go a thousand miles, while you are young, work hard and give an explanation to your future self! Move forward to a better self tomorrow!

Guess you like

Origin blog.csdn.net/aasd23/article/details/126644476