用jsp實(shí)現(xiàn)一個(gè)簡(jiǎn)單的購(gòu)物車web應(yīng)用系統(tǒng)(Using JSP to implement a simple shopping cart web application system)_第1頁
用jsp實(shí)現(xiàn)一個(gè)簡(jiǎn)單的購(gòu)物車web應(yīng)用系統(tǒng)(Using JSP to implement a simple shopping cart web application system)_第2頁
用jsp實(shí)現(xiàn)一個(gè)簡(jiǎn)單的購(gòu)物車web應(yīng)用系統(tǒng)(Using JSP to implement a simple shopping cart web application system)_第3頁
用jsp實(shí)現(xiàn)一個(gè)簡(jiǎn)單的購(gòu)物車web應(yīng)用系統(tǒng)(Using JSP to implement a simple shopping cart web application system)_第4頁
用jsp實(shí)現(xiàn)一個(gè)簡(jiǎn)單的購(gòu)物車web應(yīng)用系統(tǒng)(Using JSP to implement a simple shopping cart web application system)_第5頁
已閱讀5頁,還剩18頁未讀, 繼續(xù)免費(fèi)閱讀

付費(fèi)下載

VIP免費(fèi)下載

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、用jsp實(shí)現(xiàn)一個(gè)簡(jiǎn)單的購(gòu)物車web應(yīng)用系統(tǒng)(Using JSP to implement a simple shopping cart web application system)1. in the establishment of their own WEB project, the establishment of packet shopcart.dto, in the corresponding package to add class Product.java, ShopCart.javaThe 1./* class Product.2.3.package shopcart.dto;

2、4.5.import java.io.Serializable;6.7.public class Product implements Serializable8.9. private String ID; / / String name private 10. product identification product name 11. private String; / / description; / / private double price 12. product description; / / public 13.14. Product (price)15. 16.17.18

3、. public Product (String ID, String name, String description, double price)19. 20. this.id = id;21. = name;22. this.description = description;23. this.price = price;24.25.26. public void setId (String ID)27. 28. this.id = id;29.30.31. public void setName (String name)32. 33. = na

4、me;34.35.36. public void setDescription (String description)37. 38. this.description = description;39.40.41. public void setPrice (double price)42. 43. this.price = price;44.45.46. public String getId ()47. 48. return id;49.50.51. public String getName ()52. 53. return name;54.55.56. public String g

5、etDescription ()57. 58. return description;59.60.61. public double getPrice ()62. 63. return price;64.65.The 66./* class ShopCart.67.68.package shopcart.dto;69.70.import java.io.Serializable;71.import java.util.*;72.73.public class ShopCart implements Serializable74.75. public ShopCart ()76. 77.78.7

6、9. private List cart = null;80.81. / * *82. * add a product to a shopping cart83. * param product Product84.85. public void addProductToCart (Product product)86. 87. if (CART = null)88. cart = new ArrayList ();89. Iterator it = cart.iterator ();90. while (it.hasNext ()91. 92. Product item = (Product

7、) it.next ();93. if (item.getId ().Equals (product.getId ()94. 95. return;96.97.98. cart.add (product);99.100.101. / * *102. * remove a product from a shopping cart103. * param productId String product ID104.105. public void removeProductFromCart (String productId)106. 107. if (CART = null)108。返回;10

8、9。迭代器它=車。();110。而(它。hasnext())111。112。產(chǎn)品名稱=(產(chǎn)品),next();113。如果(項(xiàng)目。getid()。等于(ID)114。115。remove()它;116。返回;117。118。119。120.121。/ * *122。*計(jì)算購(gòu)物車中的商品價(jià)格123。*“雙倍返還商品價(jià)格總數(shù)124。* /125。公眾的雙重getallproductprice()126。127。如果(CART = NULL)128。返回0;129。雙總價(jià)= 0;130。迭代器它=車。();131。而(它。hasnext())132。133。產(chǎn)品名稱=(產(chǎn)品),next();134。

9、總價(jià)= getprice()項(xiàng)目;135。136。返回總價(jià);137。138.139。/ * *140。*返回購(gòu)物車所有產(chǎn)品信息141。*返回表142。* /143。上市g(shù)etallproductsfromcart()144。145。返回的車;146。147。148.149.2。在Webroot的目錄下添加包購(gòu)物車在里邊添加showproductsjsp.jsp shoppingjsp.jsp shopcartjsp.jspshowproductsjsp.jsp :1。<% 頁面語言=“java”進(jìn)口=“java util。*”pageencoding =“GB18030”%>2。&

10、lt;% 頁導(dǎo)入=“購(gòu)物車。DTO。*“% >3,< %4。字符串路徑= getcontextpath()請(qǐng)求;5。字符串修改表情=請(qǐng)求。getscheme() +“/”6。+要求。getservername() +“:”+要求。getserverport()7。+路徑“/”;8。% >9.10 < <!DOCTYPE html PUBLIC“- / / / / W3C HTML 4.01 DTD的過渡/連接”>11、< html >12。<head>13。<基地href =”< % =修改表情% >”>14.

11、15。<標(biāo)題>我的JSP的showproductsjsp。JSP的起始頁</標(biāo)題>16.17。<meta http-equiv =“語用”內(nèi)容=“不緩存”>18。<meta http-equiv =“緩存控制”內(nèi)容=“不緩存”>19。<meta http-equiv =“過期”內(nèi)容=“0”>20。<meta http equiv =“關(guān)鍵詞”content=“關(guān)鍵詞,關(guān)鍵詞1,2關(guān)鍵詞3”>21。<meta http equiv =“描述”內(nèi)容=“這是我的網(wǎng)頁”>22。<!23。<鏈接rel=“樣式

12、表”type=“文本/ CSS“href =”風(fēng)格。CSS”>24。->25.26。<頭/ >27.28。<體背景顏色=“# ffffff”>29。< %30。圖hashmap() =新產(chǎn)品;31。產(chǎn)品。把(“001”,新產(chǎn)品(“001”、“MP3播放器”,32?!毙Ч懿诲e(cuò)的MP3播放器,存儲(chǔ)空間達(dá)1GB的“,999);33。產(chǎn)品.把(“002”,新產(chǎn)品(“002”、“數(shù)碼相機(jī)”、“象素500萬,10倍光學(xué)變焦”,34。2500);35。產(chǎn)品。把(“003”,新產(chǎn)品(“003”、“數(shù)碼攝像機(jī)”,36?!?20萬象素,支持夜景拍攝,20倍光學(xué)變焦”,5

13、999);37。產(chǎn)品。把(“004”,新產(chǎn)品(“004”、“迷你MP4”,38?!笔忻嫠芤姷降淖詈玫腗P4播放器,國(guó)產(chǎn)”,1999.99);39。產(chǎn)品。把(“005”,新產(chǎn)品(“005”、“多功能手機(jī)”,40。”集MP3播放、100萬象素?cái)?shù)碼相機(jī),手機(jī)功能于一體”,2199.99);41。getservletcontext() ServletContext上下文=;42。背景。setAttribute(“產(chǎn)品”,產(chǎn)品);43。%>44。<h1>45。產(chǎn)品顯示46。< >47。< a href =“/ helloapp /購(gòu)物車/ showcartjsp .

14、jsp”>查看購(gòu)物車</a>48.49。<表名稱=“乘積”行動(dòng)=“/ helloapp /購(gòu)物車/ shoppingjsp .jsp”method=“后”>50。<輸入類型=“隱藏”名稱=“操作”值=“購(gòu)買”>51。<表格邊框=“1”=“0”>單元格之間的距離52。<表格的背景顏色=“# cccccc”>53。<表格的背景顏色=“# cccccc”>54。<公司>55。序號(hào)56。< >57。<公司>58。產(chǎn)品名稱59。< >60。<公司>61。產(chǎn)品描述62。

15、< >63。<公司>64。產(chǎn)品價(jià)格(¥)65。< >66。<公司>67。添加到購(gòu)物車68。< >69。< >70。< %71。集productidset =產(chǎn)品。keyset();72。迭代器它= productidset。();73。整數(shù)= 1;74。75。而(它。hasnext())76。字符串ID =(字符串),next();77。產(chǎn)品=(產(chǎn)品)產(chǎn)品;78。% < < > >79。<公司>80。<81。<公司>82。%產(chǎn)品。getname() %>83

16、。< >84。< td > < % =產(chǎn)品。getdescription() %>85。< >86。<公司>87。%產(chǎn)品。getprice() %TD >88。<公司>89。<輸入type=“復(fù)選框”name=“ID”90。價(jià)值=“< % =產(chǎn)品。getid() % >”>91。< >92。< >93。< % % >94。<表>95。<P>96。<輸入type=“復(fù)位”value=“全部取消”/>97。<輸入type

17、=“提交”value=“確定”/>98。< >99。<表格>100。<身體>101。102。shoppingjsp JSP :。1。<% 頁面語言=“java”進(jìn)口=“java util。*”pageencoding =“GB18030”%>2。<% 頁導(dǎo)入=“購(gòu)物車。DTO。*“% >3,< %4。字符串路徑= getcontextpath()請(qǐng)求;5。字符串修改表情=請(qǐng)求。getscheme() +“/”6。+要求。getservername() +“:”+要求。getserverport()7。+路徑“/”;8。%

18、>9.10 < <!DOCTYPE html PUBLIC“- / / / / W3C HTML 4.01 DTD的過渡/連接”>11、< html >12。<head>13。<基地href =”< % =修改表情% >”>14.15。>我的JSP“購(gòu)物”JSP的起始頁16.17。<meta http-equiv =“語用”內(nèi)容=“不緩存”>18。<meta http-equiv =“緩存控制”內(nèi)容=“不緩存”>19。<meta http-equiv =“過期”內(nèi)容=“0”>20。

19、<meta http equiv =“關(guān)鍵詞”content=“關(guān)鍵詞,關(guān)鍵詞1,2關(guān)鍵詞3”>21。<meta http equiv =“描述”內(nèi)容=“這是我的網(wǎng)頁”>22。<!23。<鏈接rel=“樣式表”type=“文本/ CSS“href =”風(fēng)格。CSS”>24。->25.26。<頭/ >27.28。<體背景顏色=“# ffffff”>29。< %30。嘗試31。響應(yīng)。setcontenttype(“text/html;字符集= GBK”);32。getsession() HttpSession myses

20、sion =請(qǐng)求;33。getservletcontext() ServletContext上下文=;34。購(gòu)物車購(gòu)物車=(購(gòu)物車)mysession getAttribute(“購(gòu)物車”);35。字符串行動(dòng)=請(qǐng)求。getParameter(“行動(dòng)”);36。如果(“刪除”)等于(動(dòng)作)37。字符串removeid =請(qǐng)求。getParameter(“removeid”);38。車removeproductfromcart(removeid);39。否則如果(動(dòng)作等于(“購(gòu)買”)40。字符串 productids =請(qǐng)求。Getparametervalues(“ID”);41.42。地圖產(chǎn)品=

21、(圖)上下文對(duì)象(“產(chǎn)品”);43。如果(CART = NULL)44。車=新shopcart();45。mysession。setAttribute(“購(gòu)物車”,車);46。47。如果(productids = = null)48。productids =新的字符串 0 ;49。50。為(int i = 0;i < productids.length;i+)51。產(chǎn)品=(產(chǎn)品)的產(chǎn)品。獲得(productids 我);52。車addproducttocart(產(chǎn)品);53。54。55。 catch(NullPointerException E)56。如printstacktrace()

22、;57。%>58。JSP頁面=“<:向前/購(gòu)物車/ showcartjsp .jsp”> < / JSP:向前>59.60。<身體>61。shopcartjsp JSP :。1。<% 頁面語言=“java”進(jìn)口=“java util。*”pageencoding =“GB18030”%>2。<% 頁導(dǎo)入=“購(gòu)物車。DTO。*“% >3,< %4。字符串路徑= getcontextpath()請(qǐng)求;5。字符串修改表情=請(qǐng)求。getscheme() +“/”+要求。getservername() +“:”+要求。getserverport() +路徑+“/”;6。% >7.8 < <!DOCTYPE html PUBLIC“- / / / / W3C HTML 4.01 DTD的過渡/連接”>9、< html >10。<head>11。<基地href =”< % =修改表情% >”>12。13。<標(biāo)題>我的JSP的showcartjsp。JSP的起始頁</標(biāo)題>14。15。<meta http-equiv =“語用”內(nèi)容=“不緩存”&

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論