您现在的位置是: 软件 > 开发者网络 > 程序方舟 > 服务器端脚本编程 > JSP专辑 > 正文


-Win xp中的多种网络
-试验试验试验试验
-用Freehand实现位图矢量化
-网络电话面面观

电子商务模型的JSP、JavaBean实现
2001-05-08· ·wayne··yesky

上一页  1 2 3 4 5 6 7 8 9  


      小结

      这样一来,JSP就能极大的扩展了 servlet 技术,由于支持 Java 脚本,JSP和Servlet就使网页设计师能够随心所欲的开发出高品质的动态网页程序。但不管怎么说,JSP也是不会代替 servlets的,因为servlets,JSP和JavaBeans在网络体系结构中起着互相补足的作用。通过遵从MVC模式, JSP应用程序能够独立地扩大或提高用于后台控制的servlet,JSP页面和现实的应用程序模型。应用程序模型能被扩展到一个两层或三层的方案,并且增加助手Bean,这都能管理JSP工作流程和支持应用程序组件之间的宽松联接。

      附录一、 InventoryBean.java类(下面我将不会对代码进行过多的解释)

      package shoppingcart;

  public class InventoryBean {

  /*
   商品名称

  */
  private static final String[] names = 
   { "牙膏", "肥皂", "毛巾", 
    "口香糖", "牙刷", "练习本", 
    "钢笔"};

  /*
   商品序列号。 
  */
  private static final int[] skus = 
   { 1, 2, 3, 4, 5, 6, 7 };

  /*
   商品每件的价格。 
  */

  private static final double[] prices = 
   { 2.50, 3.90, 5.25, 1.00, 
    3.50, 0.40, 11.80};

  private Product[] catalogue_ = null;

  private static InventoryBean inventory_ = new InventoryBean();
  private InventoryBean() {
   catalogue_ = new Product[skus.length];
   for (int i = 0; i < skus.length; i++) {
    catalogue_[i] = createProduct(skus[i]);
   }
  }

  public static Product[] getCatalogue() {
   return inventory_.catalogue_;
  }

  private Product createProduct(int sku) {
   return new Product(sku, names[sku-1], prices[sku-1]);
   }
  }

附录二、Product类

  package shoppingcart;

  public class Product implements Cloneable { 
  private int sku_ = 0;
  private String name_ = null;
  private double price_ = 0;
  private int Pieces_ = 0;

  public String toString() {
   return "商品序列号: " + sku_ + ", 商品名: " + name_ + 
   ", 单价: " + price_ + ", 件数: " + pieces_;
  }

  public Product(int sku,  String name, double price) {
   sku_ = sku;
   name_ = name;
   price_ = price;
  }

  public int getSKU() {
   return sku_;
  }

  public String getName() {
   return name_;
  }

  public double getPrice() {
   return price_;
  }

  public double getPieces() {
   return pounds_;
  }

  public void setPieces(int pieces) {
   pieces_ = pieces;
  }

  public Object clone() {
    Object dup = null;
    try {
     up = super.clone();
    }
    catch(CloneNotSupportedException ignore) { }
     return dup;
    }
  }


  附录三、ReceiptBean类

  package shoppingcart;

  import javax.servlet.*;
  import javax.servlet.http.*;

  public class ReceiptBean {
  private String name_ = null;
  private String email_ = null;
  private String address_ = null;
  private String phone_ = null;
  public ReceiptBean() {
  }
  public void setName(String name) {
  name_ = name;
  }
  public String getName() {
   return name_;
  }
  public void setEmail(String email) {
   email_ = email;
  }
  public String getEmail() {
   return email_;
  }
  public void setAddress(String address) {
   address_ = address;
  }
  public String getAddress() {
   return address_;
  }
  public void setPhone(String phone) {
   phone_ = phone;
  }
  public String getPhone() {
   return phone_;
  }
  }


上一页  1 2 3 4 5 6 7 8 9  

■ 相关内容
 JSP技术简介之二
 JSP技术简介
 Java Servlet和JSP教程之JSP 技术概述
 JSP与EJB通信
 在JavaScript程序中整合Java函数
 为Delphi提供Pack功能
 推技术聊天室的实现(上)
 使用Java实现数据报通讯过程
 Java中的两个特殊变量this和super
感谢 访问天极网,如果您觉得该文章涉及版权问题,请看这里!