当前位置:首页 > 网上商城 > 正文内容

我想做个网上图书购物商城。所用语言用Java吧。。用到SSH三层框架的。。希望能有前台和后台的功能。

访客2021-05-30 03:36:57网上商城57

首相将项目部署在tomcat中 然后运行tomcat 记住上下文的名称 之后在页面中输入相对应的url 就可以访问了

Java与网上购物的网站

京东是asp.net写的。淘宝是用php写的。
但是绝大数银行网站都是用java写的,就安全性来说,java无疑是最佳选择。
这些语言你都可以选择。

jsp购物车的代码和数据库

//购物车类ShoppingCart,仅供参考
package bookshop;
import java.util.*;
import java.sql.*;
import java.text.*;
public class ShoppingCart {
    HashMap items = null;
    public ShoppingCart() {
        items = new HashMap();
    }
    public synchronized void add(String bookID) throws Exception {
        if (items.containsKey(bookID)) 
        {
            ShoppingCartItem item = (ShoppingCartItem) items.get(bookID);
            item.quantity++;
        } 
        else 
        {
            String sql = " SELECT * FROM tb_Book WHERE bookID='" + bookID
                    + "' ";
            DBHandle dbhandle = new DBHandle();
            ResultSet rs = dbhandle.executeQuery(sql);
            ShoppingCartItem newItem = new ShoppingCartItem();
            if (rs.next()) {
                newItem.bookID=bookID;
                newItem.isbn = rs.getString("ISBN");
                newItem.bookName = rs.getString("bookName");
                newItem.bookImage = rs.getString("bookImage");
                newItem.categoryID = rs.getString("categoryID");
                newItem.author = rs.getString("author");
                newItem.price = rs.getFloat("price");
                newItem.description = rs.getString("description");
                newItem.quantity=1;
                dbhandle.closeResource();
                items.put(bookID, newItem);
            }
        }
    }

    public synchronized void setItem(String BookID, int num) {
        if (items.containsKey(BookID)) {
            ShoppingCartItem item = (ShoppingCartItem) items.get(BookID);
            item.quantity=num;
        }
    }

    public synchronized void remove(String BookID) {
        items.remove(BookID);
    }

    public synchronized Iterator getItems() {
        Collection c = items.values();
        return c.iterator();
    }

    protected void finalize() throws Throwable {
        items.clear();
    }

    public synchronized int getNumberOfItems() {
        return items.size();
    }

    public synchronized double getTotal() {
        double amount = 0.0;
        for (Iterator i = getItems(); i.hasNext();) {
            ShoppingCartItem item = (ShoppingCartItem) i.next();    
            amount += item.quantity *item.price;
        }
        return roundOff(amount);
    }

    private double roundOff(double x) {
        long val = Math.round(x * 100); // cents
        return val / 100;
    }

    public synchronized void clear() {
        items.clear();
    }

    public int payOrder(String userName, String trueName, String postcode,
            String address, String telephone, String memo) throws Exception {
        Connection conn = null;
        int orderID = 0;
        DBHandle dbhandle = new DBHandle();
        try {
            conn = dbhandle.getConnection();
            conn.setAutoCommit(false);

            Statement stmt = conn.createStatement();
            double total = getTotal();
            SimpleDateFormat dataFormat = new SimpleDateFormat(
                    "yyyy-MM-dd HH:mm:ss");
            String orderDate = dataFormat.format(new java.util.Date());
            String sql = " INSERT INTO tb_Orders(userName,trueName,address,postcode,tel,memo,totalPrice,isPay, isDeliver,orderDate)VALUES('"
                    + userName+ "','"+ trueName
                    + "','"
                    + address
                    + "','"
                    + postcode
                    + "','"
                    + telephone
                    + "','"
                    + memo
                    + "',"
                    + total + ",'0','0','" + orderDate + "' ) ";
            System.out.println(sql);
            stmt.executeUpdate(sql);
            sql = " SELECT MAX(orderID) AS maxOrderID FROM tb_Orders ";//改动
            System.out.println(sql);
            ResultSet rs = stmt.executeQuery(sql);
            rs.next();
            orderID = rs.getInt(1);
            Iterator i = getItems();
            while (i.hasNext()) {
                ShoppingCartItem item = (ShoppingCartItem) i.next();
                int quantity = item.quantity;
                String id = item.bookID;
                double price = item.price;
                sql = " INSERT INTO tb_OrderDetail(orderID,bookID,quantity,price) VALUES("
                        + orderID
                        + ","
                        + id
                        + ","
                        + quantity
                        + ","
                        + price
                        + ")";
                stmt.executeUpdate(sql);
            }
            conn.commit();
            conn.setAutoCommit(true);
        } catch (Exception ex) {
            conn.rollback();
            System.out.println(ex.getMessage());
            throw ex;
        } finally {
            dbhandle.closeResource();
        }
        return orderID;
    }
}
//图书信息类,ShoppingCartItem
package bookshop;
public class ShoppingCartItem{
    public String bookID = null;
    public String isbn = null;
    public String bookName = null;
    public float price = 0.0F;
    public String description = null;
    public String bookImage=null;
    public String author=null;
    public String categoryID=null;
    public int quantity;    
}

分享给朋友:

相关文章

目前知名的海外本土电商平台有哪些

目前知名的海外本土电商平台有哪些

现在国内外代购方便很多了各方面相对规范一些了,流程也简便很多。1、比较知名的国外站:亚马逊、易贝网、韩国乐天等。2、另外就是国内跨境电商,现在国内很多也便捷很多,比如京东全球购、海外U、天猫国际等等。对于小白还是选择国内的好一些,操作简单,...

互联网+时代,你能做好线上销售吗?

互联网+时代,你能做好线上销售吗?

互联网+线上销售即个人、企业以互联网为依托,通过运用大数据、人工智能等先进技术手段并运用心理学知识,对商品的生产、流通与销售过程进行升级改造,进而重塑业态结构与生态圈,并对线上服务、线下体验以及现代物流进行深度融合的零售模式,又称新零售。...

法国运动品牌有哪些?哪个品牌质量最好

法国运动品牌有哪些?哪个品牌质量最好

一、法国运动品牌有哪些?哪个品牌质量最好 法国运动品牌有法国公鸡(Le Coq Sportif)、Eider Cepheu、迪卡侬、BABOLAT(百保力)、所罗门。质量最好是迪卡侬。 1、法国公鸡(Le Coq Sportif)  是来自...

生鲜电商平台有没有比较好的推荐?

生鲜电商平台有没有比较好的推荐?

生鲜电商的出现,电商与配送服务的结合,给我们的生活带来了很多便利,例如:最大的好处就是让我们足不出户打开房门就有菜吃,这无疑是更方便了大家的生活。随着电商平台的增加,我们见证了一家家生鲜电商的崛起。 就目前而言,市面上主要有这九大生鲜平台:...

如何快速设计产品列表页

如何快速设计产品列表页

1.展示基本信息正因为商品列表页相较于其他页面会显得有些拥挤,因此更应该抱着在限制的区域范围内展现最有用的信息的心态来设计网页。正在浏览商品列表页的用户也许对商品的细节描述并不是很在意,此时的浏览模式更偏于走马观花,因此,简单扼要的图片、商...

aj11low黑白gs鞋底氧化会变成什么颜色?

aj11low黑白gs鞋底氧化会变成什么颜色?

aj11 low黑白gs鞋底氧化后会变在浅黄,严重一点的就会变成深黄色的。 氧化(oxidation): 狭义地,氧元素与其他的物质元素发生的化学反应,称其为氧化,也是一种重要的化工单元过程。广义的氧化,指物质失电子(氧化数升高)的过...