JSP training of Shopping Cart example

Source: Internet
Author: User

Goal:


L MASTER the information how to store the shopping cart;


L MASTER The realization of the common function of shopping cart.


main content:


L First analyzes the general process of user online shopping;


L Describes what data structure is used to store shopping information;


L Write shopping interface;


L completes the function of adding items to the shopping cart.


1, the general process of user online shopping

If you are interested in an item in the process of browsing the item,
will be added to the shopping cart (shopping basket), you can always view the information in the cart, if you do not want an item, you can delete, or modify the number of items, or the entire empty cart, you can continue to select items to add to the cart. Finally, users can purchase these items, after entering personal shipping address information and set up trading methods, you can generate orders. The administrator of the Web site can manage orders.


This example simulates this process, but simplifies it: only select items in the list of items to add to the cart. Make sure that you do not need to set up trading methods and payments after purchasing. The actual processing process can be done using the features we described earlier.


2, Shopping cart information organization


Because shopping cart information can be accessed throughout the course of a user's visit to the site, the shopping Cart object should be stored in session.


Because the user buys the item the kind and the quantity is uncertain, therefore needs to use a suitable data structure storage, we choose ArrayList.


Each item is involved in quantity, it needs to be encapsulated, the item and quantity are packaged into a shopping item, the item is used, each item corresponds to an item and the quantity of the item.


need to write an item class that represents the basic information of an item.


Reference code is as follows:


2.1 Goods class


This class contains two methods that are related to paging display. The Dbbean used is described earlier.


package JavaBean;


 


import java.util.ArrayList;


import java.sql.*;


 


public class goods


{


private String goodsid;


private String goodsname;


Private float price;


//Item number


public void Setgoodsid (String goodsid)


   {


this.goodsid = goodsid;


   }


 


public String getgoodsid ()


   {


return Goodsid;


   }


 


//Item name


public void Setgoodsname (String goodsname)


   {


this.goodsname = goodsname;


  }


 


Public String getgoodsname ()


   {


return goodsname;


   }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.