您的位置首页百科问答 jsp购物车代码 Simone 发布于 2024-06-19 02:28:45 569 阅读 jsp购物车代码的有关信息介绍如下://shopping.html shopping stor please select the item that you want to buy book:old man and the sea x-box game machine mp3 player cce book:jsp programming cd "the endless love" dvd "gone with the wind" ------------------------------------------------------------------//carts.jsp<%@page contentType="text/html;charset=ISO8859_1" %> <% cart.processRequest(); %> you have chosen these items: <% String []items=cart.getItems(); for(int i=0;i <%=items[i] %> <% } %> <%@include file="shopping.htm" %>---------------------------------------------------------------------//DummyCart.javapackage test;import javax.servlet.http.*;import java.util.Vector;import java.util.Enumeration;public class DummyCart{ Vector v = new Vector(); String submit=null; String item= null; private void addItem(String name) { v.addElement(name); } private void removeItem(String name) { v.removeElement(name); } public void setItem(String s) { item=s; } public void setSubmit(String s) { submit=s; } public String[] getItems() { String []s=new String[v.size()]; v.copyInto(s); return s; } public void processRequest() { if(submit==null) addItem(item); if(submit.equals("add")) addItem(item); else if (submit.equals("remove")) removeItem(item); reset(); } private void reset() { submit=null; item=null; } }----------------------------------------------------------------------上面是一个简单的例子,功能都能实现,对网页效果要求更漂亮些的可做一些修改。