• 大小: 21KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: Java
  • 标签: jsp  

资源简介

jsp+javabean+mysql,很好的jsp源码

资源截图

代码片段和文件信息

package cart;

import java.util.*;
import database.BookDetails;


public class ShoppingCart {
    HashMap items = null;
    int numberOfItems = 0;

    public ShoppingCart() {
        items = new HashMap();
    }

    public synchronized void add(String bookId BookDetails book) {
        if (items.containsKey(bookId)) {
            ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId);
            scitem.incrementQuantity();
            System.out.println(“in add quantity is “ + scitem.getQuantity());
        } else {
            ShoppingCartItem newItem = new ShoppingCartItem(book);
            items.put(bookId newItem);
            System.out.println(“in add quantity is “ + newItem.getQuantity());
        }
        
    }

    public synchronized void remove(String bookId) {
        if (items.containsKey(bookId)) {
            ShoppingCartItem scitem = (ShoppingCartItem) items.get(bookId);
            scitem.decrementQuantity();

            if (scitem.getQuantity() <= 0) {
                items.remove(bookId);
            }

            numberOfItems--;
        }
    }

    public synchronized List getItems() {
        List results = new ArrayList();
        Iterator items = this.items.values().iterator();

        while (items.hasNext()) {
            results.add(items.next());
        }

        return (results);
    }

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

    public synchronized int getNumberOfItems() {
        numberOfItems = 0;

        for (Iterator i = getItems()
                              .iterator(); i.hasNext();) {
            ShoppingCartItem item = (ShoppingCartItem) i.next();
            numberOfItems += item.getQuantity();
            System.out.println(“number of items is “ + numberOfItems);
        }

        return numberOfItems;
    }

    public synchronized double getTotal() {
        double amount = 0.0;

        for (Iterator i = getItems()
                              .iterator(); i.hasNext();) {
            ShoppingCartItem item = (ShoppingCartItem) i.next();
            BookDetails bookDetails = (BookDetails) item.getItem();

            amount += (item.getQuantity() * bookDetails.getPrice());
        }

        return roundOff(amount);
    }

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

        return val / 100.0;
    }

    public synchronized void clear() {
        System.err.println(“Clearing cart.“);
        items.clear();
        numberOfItems = 0;
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        362  2009-09-26 10:03  BS\.classpath

     文件        279  2009-09-26 10:03  BS\.mymetadata

     文件       1220  2009-09-26 10:09  BS\.project

     文件       1105  2009-09-26 10:09  BS\WebRoot\bookcashier.jsp

     文件       1883  2009-09-26 10:09  BS\WebRoot\bookcatalog.jsp

     文件       1207  2009-09-26 10:09  BS\WebRoot\bookdetails.jsp

     文件       1518  2009-09-26 10:05  BS\WebRoot\bookordererror.jsp

     文件        907  2009-09-26 10:09  BS\WebRoot\bookreceipt.jsp

     文件       2900  2009-09-26 10:09  BS\WebRoot\bookshowcart.jsp

     文件       1307  2009-09-26 10:14  BS\WebRoot\bookstore.jsp

     文件        253  2009-09-26 10:05  BS\WebRoot\global.jsp

     文件        298  2009-09-26 10:05  BS\WebRoot\gobookreceipt.jsp

     文件        381  2009-09-26 10:03  BS\WebRoot\WEB-INF\web.xml

     文件        452  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\exception\BookNotFoundException.class

     文件        455  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\exception\BooksNotFoundException.class

     文件        431  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\exception\OrderException.class

     文件       1456  2009-09-26 10:19  BS\WebRoot\WEB-INF\classes\database\BookDB.class

     文件       5116  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\database\BookDBAO.class

     文件       2497  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\database\BookDetails.class

     文件        555  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\config\Constants.class

     文件       3143  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\cart\ShoppingCart.class

     文件        881  2009-09-26 10:04  BS\WebRoot\WEB-INF\classes\cart\ShoppingCartItem.class

     文件         39  2009-09-26 10:03  BS\WebRoot\meta-INF\MANIFEST.MF

     文件        194  2009-09-26 10:04  BS\src\exception\BookNotFoundException.java

     文件        197  2009-09-26 10:04  BS\src\exception\BooksNotFoundException.java

     文件        173  2009-09-26 10:04  BS\src\exception\OrderException.java

     文件        885  2009-09-26 10:19  BS\src\database\BookDB.java

     文件       5312  2009-09-26 10:04  BS\src\database\BookDBAO.java

     文件       2195  2009-09-26 10:04  BS\src\database\BookDetails.java

     文件        297  2009-09-26 10:04  BS\src\config\Constants.java

............此处省略21个文件信息

评论

共有 条评论