好烦小窝

在线服装销售系统 - JavaWeb

一、成品:

二、相关代码:

数据库文件下载点我下载

三、类文件(test.pojo):

C.java

package test.pojo;

import java.io.Serializable;

public class C implements Serializable {
    private int cid;
    private String cname;

    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    private String cnumber;
    private String selldate;
    private float realprice;
    private float cutprice;
    private String description;

//cid 属性的getter()和setter()方法
    public int getCid() {
        return cid;
    }

    public void setCid(int cid) {
        this.cid = cid;
    }
    // cname属性的getter()和setter()方法

    public String getCnumber() {
        return cnumber;
    }

    public void setCnumber(String cnumber) {
        this.cnumber = cnumber;
    }

    public String getSelldate() {
        return selldate;
    }

    public void setSelldate(String selldate) {
        this.selldate = selldate;
    }

    public float getRealprice() {
        return realprice;
    }

    public void setRealprice(float realprice) {
        this.realprice = realprice;
    }

    public float getCutprice() {
        return cutprice;
    }

    public void setCutprice(float cutprice) {
        this.cutprice = cutprice;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}

CI.java

package test.pojo;

import java.io.Serializable;

public class CI implements Serializable {
    private C item;
    private int amount = 0;

    public CI() {
        super();
    }

    public CI(C newClothes, int num) {
        super();
        if (num > 0) {
            item = newClothes;
            amount = num;
        }
    }

    public void InAmount() {
        amount++;
    }

    public void DeAmount() {
        amount--;
    }

    public C getItem() {
        return item;
    }

    public void setItem(C item) {
        this.item = item;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

}

CP.java

package test.pojo;
import javax.sql.DataSource;
public class CP {
private DataSource dataSource = null;
public DataSource getDataSource() {
    return dataSource;
}
public void setDataSource(DataSource dataSource) {
    this.dataSource=dataSource;
    
}
}

SC.java

package test.pojo;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;

public class SC implements Serializable {
    private HashMap items;
    private int itemAmount;

    public SC() {
        super();
        items = new HashMap();
        itemAmount = 0;
    }

    public synchronized void add(int cid, C clothes, int num) {
        if (items.containsKey(cid)) {
            items.remove(cid);
            CI newitem = new CI(clothes, num);
            items.put(cid, newitem);
        } else {
            CI newitem = new CI(clothes, num);
            items.put(cid, newitem);
            itemAmount++;
        }
    }
    public synchronized void remove(int cid) {
        if(items.containsKey(cid)) {
            items.remove(cid);
        }
    }
    public synchronized Collection getItems() {
        return items.values();
    }
    protected void finalize() {
        items.clear();
    }
    public synchronized int getItemAmount() {
        return itemAmount;
    }
    public void clear() {
        items.clear();
        itemAmount = 0;
    }
}

四、xml文件

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <property name="url">
            <value>jdbc:mysql://localhost:3306/clothing</value>
        </property>
        <property name="username">
            <value>root</value>
        </property>
        <property name="password">
            <value>123456</value>
        </property>
    </bean>
    *部分内容已隐藏* *请前往底部查看~* ^v^

五、JSP文件

add.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="test.pojo.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>购买商品</title>
<style>
.top {
    font-size: 18px;
}

.tabletop {
    font-size: 16px;
    color: #3991D0;
    background-color: #CCCCCC;
    border: 2px solid #666666;
}

.tablecontent {
    font-size: 16px;
    color: #000000;
    border-bottom-width: 1px;
    border-bottom-color: #666666;
    border-bottom-style: solid;
}

.linkstyle {
    text-decoration: none;
}
</style>
</head>
<body bgcolor="#FFFFFF">
        *部分内容已隐藏* *请前往底部查看~*
    <%
    String addpid = null;
    addpid = request.getParameter("add");
    C temp = null;
    int count = 1;
    String confirm = request.getParameter("confirm");
    if (confirm == null || confirm.equals("")) {
        confirm = "none";
    }
    if ((addpid != null) && (!addpid.equals(""))) {
        temp = (C) session.getAttribute(addpid);
        if (temp == null || temp.equals("")) {
            response.sendRedirect("list.jsp");
        }
    }else{
            response.sendRedirect("list.jsp");
    }
    if(confirm.equalsIgnoreCase("true")){
        if(request.getParameter("amount")!=null){
            count = new Integer(request.getParameter("amount").trim()).intValue();
        }
    int iaddpid = Integer.parseInt(addpid);
    shopcart.add(iaddpid,temp,count);
    response.sendRedirect("list.jsp");
    }
    else if(confirm.equals("false"))
    {
        session.removeAttribute(addpid);
        response.sendRedirect("list.jsp");
    }
    else{
        
    %>
    <form action="add.jsp" method="get">
        <table align="center">
            <thead>
                <center>
                    <p class="top">修改购买服装的数量并把他们加入您的购物车</p>
                </center>
            </thead>
            <tr>
                <td class="tabletop">商品名称</td>
                <td class="tabletop">商品编号</td>
                <td class="tabletop">上架时间</td>
                <td class="tabletop">定价</td>
                <td class="tabletop">会员价</td>
                <td class="tabletop">数量</td>
                <td class="tabletop">小计</td>
            <tr>
    *部分内容已隐藏* *请前往底部查看~*
                <td class="tablecontent"><input type=text size=2 name="amount"
                    value=<%=count %>></td>
                <td class="tablecontent"><%=count*(temp.getRealprice()) %></td>
            </tr>
            <input type="hidden" name="confirm" value="true">
            <input type="hidden" name="add" value="<%=addpid %>">
            <tr>
                <td style="border: 2px solid" colspan="2" align="center"><a
                    href="list.jsp" class="linkstyle">先不买这个商品</a>
                <td style="border: 2px solid" colspan="3" align="center"><a
                    href="showcart.jsp" class="linkstyle">查看购物车</a>
                <td style="border: 2px solid" colspan="3" align="center"><input
                    type="submit" size=2 name="buy" value="确定购买"></td>
            </tr>
        </table>
    </form>
    <%} %>
</body>
</html>

putintocart.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page
    import="java.sql.*,javax.sql.DataSource,org.springframework.context.*,org.springframework.context.support.*,test.pojo.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<body bgcolor="#FFFFFF">
    <jsp:useBean id="shopcart" scope="session" class="test.pojo.SC" />
    *部分内容已隐藏* *请前往底部查看~*
</body>
</html>

showcart.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.*,test.pojo.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查看购物车</title>
<style>
.top {
    font-size: 18px;
}

.tabletop {
    font-size: 16px;
    color: #3991D0;
    background-color: #CCCCCC;
    border: 2px solid #666666;
}

.tablecontent {
    font-size: 16px;
    color: #000000;
    border-bottom-width: 1px;
    border-bottom-color: #666666;
    border-bottom-style: solid;
}

.linkstyle {
    text-decoration: none;
}
</style>
</head>
<body bgcolor="#FFFFFF">
    *部分内容已隐藏* *请前往底部查看~*
    <table align=center>
        <tr>
            <td class="top">您的购物车已被清空 <a href="list.jsp">返回服装列表</a></td>
        </tr>
    </table>
    <%
    }
    if (shopcart.getItemAmount() > 0) {
    %>
    <table align=center border=0>
        <thead align="center">
            <h2 class="top">您在购物车中加入了如下服装商品</h2>
            *部分内容已隐藏* *请前往底部查看~*
        </thead>
        *部分内容已隐藏* *请前往底部查看~*
        <tr>
            <td class="tablecontent"><%=c.getCname()%></td>
            <td class="tablecontent"><%=c.getCnumber()%></td>
            <td class="tablecontent"><%=c.getSelldate()%></td>
            <td class="tablecontent"><%=c.getRealprice()%></td>
            <td class="tablecontent"><%=c.getCutprice()%></td>
            <td class="tablecontent"><%=ci.getAmount()%></td>
            <td class="tablecontent"><a
                href="add.jsp?amount=<%=c.getRealprice() * ci.getAmount()%>&add=<%=c.getCid()%>"
                class="linkstyle">修改数量</a></td>
        </tr>
        <%
        }
        %>
        <tr align=center>
            <td colspan="4" style="border: 2px solid"><a href="list.jsp"
                class="linkstyle">继续购买</a></td>
            <td colspan="50" style="border: 2px solid"><a
                href="showcart.jsp?clear=true" class="linkstyle">清空购物车</a></td>
        </tr>
    </table>
    *部分内容已隐藏* *请前往底部查看~*
</body>
</html>

list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page
    import="java.sql.*,javax.sql.DataSource,org.springframework.context.*,org.springframework.context.support.*,test.pojo.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>服装列表</title>
<style>
.clothesname {
    font-size: 20px;
    line-height: 30px;
    color: #CC9900;
}

.description {
    font-size: 13px;
    color: #FF0000;
    background-color: #CCCCCC;
}

.common {
    font-size: 14px;
    color: #333333;
}
</style>
</head>
<body>
    *部分内容已隐藏* *请前往底部查看~*
    <table width="778" border="0" aligin="center">
        <thead>
            <tr>
                <td align="center">所有新品服装列表</td>
            </tr>
        </thead>
    *部分内容已隐藏* *请前往底部查看~*
        <tr>
            <td>
                <table width="778" border="0">
                    <tr>
                        <td width="100" height="110"><img src="1.png"></td>
                        <td width="100%">
                            <table width="100%" border="0">
                                <tr>
                                    <td class="clothesname">&nbsp;&nbsp;商品名称:<%=rs.getString("cname")%></td>
                                </tr>
                                <tr>
                                    <td class="description"><%=rs.getString("description")%></td>
                                </tr>
                                <tr>
                                    <td class="common">&nbsp;&nbsp;商品编号:<%=rs.getString("cnumber")%></td>
                                </tr>
                                <tr>
                                    <td class="common">&nbsp;&nbsp;上架时间:<%=rs.getString("selldate")%></td>
                                </tr>
                                <tr>
                                    <td class="common">&nbsp;&nbsp;定价:<%=rs.getFloat("realprice")%></td>
                                </tr>
                                <tr>
                                    <td class="common">&nbsp;&nbsp;会员价:<%=rs.getFloat("cutprice")%></td>
                                </tr>
                                    *部分内容已隐藏* *请前往底部查看~*
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td height="1" width="778" colspan="2"><hr></td>
        </tr>
        <%
        }
        %>
    
</body>
</html>

六、完整源代码请评论后查看哈

[hide]

完整版下载:


[file url="https://pan.innyun.cn/down.php/8b887f6941f1e2469cc1783b3d4ab553.war&javaweb123123"]Inn云网盘下载[/file]
提示:下载后请解压到工作目录,可行运行环境:tomcat8.5+mysql [/hide]

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »