首页技术购物车代码html(html购物车页面代码)

购物车代码html(html购物车页面代码)

编程之家2026-06-251007次浏览

大家好,今天来为大家解答购物车代码html这个问题的一些问题点,包括html购物车页面代码也一样很多人还不知道,因此呢,今天就来为大家分析分析,现在让我们一起来看看吧!如果解决了您的问题,还望您关注下本站哦,谢谢~

购物车代码html(html购物车页面代码)

怎样用PHP编个购物车的程序

简单说了,可以用Dreamweaver做网页开发平台,PHPnow打包套件作为后台,包括Apache(作为服务器)+PHP(作为PHP库资源)+MySQL(作为数据库环境)。要在数据库的添加表单等等操作,在PhpAdmin下登录进入MySQL。

编辑网页的内容会在一个叫做htdocs的文件夹内,编辑数据库的内容会在一个叫data的文件夹内。

用Dreamweaver时要设置PHPnow的路径作为站点。

jsp网上购物代码及操作!

1.index.jsp登陆界面:

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

<%

购物车代码html(html购物车页面代码)

String path= request.getContextPath();

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%session.invalidate();%><%--销毁所有session对象--%>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

购物车代码html(html购物车页面代码)

<head>

<base rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="<%=basePath%>">

<title>购物车</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="styles.css">

-->

</head>

<body>

<center>

<hr>

请输入用户名,默认的为Guest

<form action="checklogin.jsp" mothod=get>

<table width="40%" border="1">

<tr bgcolor="#336600">

<td><div align="center"><font color="FFFFFF">用户登陆</font></div></td>

</tr>

<tr align="center" bgcolor="#CCCCCC">

<td>用户名:<input type="password" name="userID"></td>

</tr>

<tr align="center" bgcolor="#CCCCCC">

<td>口令:<input type="password" name="password"></td>

</tr>

<tr align="center" bgcolor="#CCCCCC">

<td><input type="submit" value="登陆"></td>

</tr>

</table>

</form>

</center>

</body>

</html>

2.checklogin.jsp登陆认证页面:

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

<%

String path= request.getContextPath();

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<jsp:useBean id="Car" class="web.Car" scope="session">

<jsp:setProperty property="*" name="Car"/>

</jsp:useBean>

<%session.setMaxInactiveInterval(900);%><%--设置session超时为30分--%>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="<%=basePath%>">

<title>My JSP'checklogin.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="styles.css">

-->

</head>

<body>

<%

String nextpage;

if(Car.getUserID().equals("Guest"))

nextpage="car.jsp";

else

nextpage="index.jsp";

%>

<jsp:forward page="<%=nextpage%>"></jsp:forward>

</body>

</html>

3.car.jsp购物车页面

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

<%

String path= request.getContextPath();

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%@ page import="java.util.*"%>

<%@ page import="web.Car"%>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="<%=basePath%>">

<title>购物车</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="styles.css">

-->

</head>

<body>

<br><%@ include file="header.jsp"%>

<hr>

<font size="2">

<jsp:useBean id="Car" class="web.Car" scope="session">

</jsp:useBean>

<p><font color="#804040" face="楷体_GB2312">

<strong>百货商场,请尽情的选购商品添加到购物车!</strong>

</font>

<%String str=response.encodeRedirectURL("add.jsp");%>

<form action="<%=str%>" method="post" name="form">

<select name="item" value="没选择">

<option value="TV">电视机</option>

<option value="apple">苹果</option>

<option value="coke">可口可乐</option>

<option value="milk">牛奶</option>

<option value="tea">茶叶</option>

</select>

<p><font color="#804040" face="楷体_GB2312">

输入购买的数量:

</font>

<input type="text" name="mount">

<p>

<input type="radio" name="unit" value="个">个

<input type="radio" name="unit" value="公斤">公斤

<input type="radio" name="unit" value="台">台

<input type="radio" name="unit" value="瓶">瓶<p>

<input type="submit" value="提交添加">

</form>

<p><font color="#804040" face="楷体_GB2312">你的购物车里有如下商品:</font>

<font color="#FF8040" size="2">

<%

Hashtable list=Car.list_h();

Enumeration enums=list.elements();

while(enums.hasMoreElements()){

String goods=(String) enums.nextElement();

byte b[]=goods.getBytes("ISO-8859-1");

goods=new String(b);

out.println("<br>"+goods);

}

%>

</font>

<% String strl=response.encodeRedirectURL("selectRemoveGoods.jsp");%>

<form action="<%=strl%>" method="post" name="form">

<input type="submit" value="修改购物车中的商品">

</form>

</font>

<%@ include file="tail.jsp"%>

</body>

</html>

4.add.jsp增加物品:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path= request.getContextPath();

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="<%=basePath%>">

<title>购物车</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="styles.css">

-->

</head>

<body>

<%@ include file="header.jsp"%>

<hr>

<font size="2">

<jsp:useBean id="Car" class="web.Car" scope="session"></jsp:useBean><br>

<jsp:setProperty name="Car" property="*"/>

<%Car.add_h();%>

<font face="楷体_GB2312">

<font color="#FF8040" size="2">

<p>您的购物车有如下商品:

<%

Hashtable list=Car.list_h();

Enumeration enums=list.elements();

while(enums.hasMoreElements()){

String goods=(String) enums.nextElement();

byte b[]=goods.getBytes("ISO-8859-1");

goods=new String(b);

out.println("<br>"+goods);

}

%>

</font>

<%String str=response.encodeRedirectURL("car.jsp");%>

<br>

<form action="<%=str%>" method="post" neme="form">

<input type="submit" value="继续购物">

</form>

<%String strl=response.encodeRedirectURL("selectRemoveGoods.jsp");%>

<br>

<form action="<%=strl%>" method="post" neme="form">

<input type="submit" value="修改购物车中的物品">

</form>

</font>

</font>

<%@ include file="tail.jsp"%>

</body>

</html>

5.selectRemoveGoods.jsp选择删除商品:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path= request.getContextPath();

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%@ page import="java.util.*"%>

<%@ page import="web.Car"%>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="<%=basePath%>">

<title>购物</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="styles.css">

-->

</head>

<body>

<br><%@ include file="header.jsp"%>

<hr>

<jsp:useBean id="Car" class="web.Car" scope="session">

</jsp:useBean><br>

<p>选择从购物车中删除的物品:

<%String str=response.encodeRedirectURL("removeWork.jsp");%>

<form action="<%=str%>" method="post" name="form">

<select name="deleteitem" size="1">

<option value="TV">电视机</option>

<option value="apple">苹果</option>

<option value="coke">可口可乐</option>

<option value="milk">牛奶</option>

<option value="tea">茶叶</option>

</select>

<input type="submit" value="提交删除">

</form>

<font face="楷体_GB2312">

<font color="#FF8040" size="2">

<p>您的购物车有如下商品:

<%

Hashtable list=Car.list_h();

Enumeration enums=list.elements();

while(enums.hasMoreElements()){

String goods=(String) enums.nextElement();

byte b[]=goods.getBytes("ISO-8859-1");

goods=new String(b);

out.println("<br>"+goods);

}

%>

</font></font>

<%String strl=response.encodeRedirectURL("car.jsp");%>

<form action="<%=strl%>" method="post" neme="form">

<input type="submit" value="继续购物">

</form>

<%@include file="tail.jsp"%>

</body>

</html>

6.removeWork.jsp删除页面:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%

String path= request.getContextPath();

String basePath= request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<%@ page import="java.util.*"%>

<%@ page import="web.Car"%>

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<base rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="<%=basePath%>">

<title>购物车</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" href="styles.css">

-->

</head>

<body>

<%@include file="header.jsp"%>

<hr>

<font size="2">

<jsp:useBean id="Car" class="web.Car" scope="session">

</jsp:useBean><br>

<%String str=response.encodeRedirectURL("removeWork.jsp");%>

<%String name=request.getParameter("deleteitem");

if(name==null)

name="";

byte c[]=name.getBytes("ISO-8859-1");

name=new String(c);

Car.dele_h(name);

out.println("您删除了货物"+name);%>

</font>

<font face="楷体_GB2312">

<font color="#FF8040" size="2">

<p>您的购物车有如下商品:

<%

Hashtable list=Car.list_h();

Enumeration enums=list.elements();

while(enums.hasMoreElements()){

String goods=(String) enums.nextElement();

byte b[]=goods.getBytes("ISO-8859-1");

goods=new String(b);

out.println("<br>"+goods);

}

%>

</font></font>

<%String strp=response.encodeRedirectURL("car.jsp");%>

<form action="<%=strp%>" method="post" neme="form">

<input type="submit" value="继续购物">

</form>

<%String strl=response.encodeRedirectURL("selectRemoveGoods.jsp");%>

<form action="<%=strl%>" method="post" neme="form">

<input type="submit" value="修改购物车中的物品">

</form>

</body>

</html>

7.header.jsp页面头部:

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

<center>

========================================================================<br>

购物车系统<br>

=======================================================================<br>

WELCOME!

<jsp:getProperty name="Car" property="userID"/>

当前时间是:

<%=new java.util.Date().toLocaleString()%>

<br>

</center>

8.tail页面尾部

<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

<center>

<hr>

JSP+TOMCAT购物系统

</center>

9.Car.java类

package web;

import java.util.*;

import java.io.*;

public class Car implements Serializable{

Hashtable list=new Hashtable();//散列表,商品列表

String item="Welcome";

int mount=0;//商品数量

String unit=null;//商品单位

String userID;//用户

public void Car(){

}

public void setItem(String item){

this.item= item;

}

public void setMount(int mount){

this.mount= mount;

}

public void setUnit(String unit){

this.unit= unit;

}

public String getUserID(){

return userID;

}

public void setUserID(String userID){

this.userID= userID;

}

public Hashtable list_h(){

return list;

}

public void dele_h(String s){

list.remove(s);

}

public void add_h(){

String str="Name:"+item+"Mount:"+mount+"Unit:"+unit;

list.put(item, str);

}

}

java 如何编写购物车

用Vector或者是HashMap去装

<下面有部分代码你去看吧>

package com.aptech.restrant.DAO;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Set;

import java.sql.Connection;

import com.aptech.restrant.bean.CartItemBean;

import com.aptech.restrant.bean.FoodBean;

public class CartModel{

private Connection conn;

public CartModel(Connection conn){

this.conn=conn;

}

/**

*得到订餐列表

*

*@return

*/

public List changeToList(Map carts){

//将Set中元素转换成数组,以便使用循环进行遍历

Object[] foodItems= carts.keySet().toArray();

//定义double变量total,用于存放购物车内餐品总价格

double total= 0;

List list= new ArrayList();

//循环遍历购物车内餐品,并显示各个餐品的餐品名称,价格,数量

for(int i= 0; i< foodItems.length; i++){

//从Map对象cart中取出第i个餐品,放入cartItem中

CartItemBean cartItem=(CartItemBean) carts

.get((String) foodItems[i]);

//从cartItem中取出FoodBean对象

FoodBean food1= cartItem.getFoodBean();

//定义int类型变量quantity,用于表示购物车中单个餐品的数量

int quantity= cartItem.getQuantity();

//定义double变量price,表示餐品单价

double price= food1.getFoodPrice();

//定义double变量,subtotal表示单个餐品总价

double subtotal= quantity* price;

////计算购物车内餐品总价格

total+= subtotal;

cartItem.setSubtotal(subtotal);

cartItem.setTotal(total);

list.add(cartItem);

}

return list;

}

/**

*增加订餐

*/

public Map add(Map cart, String foodID){

//购物车为空

if(cart== null){

cart= new HashMap();

}

FoodModel fd= new FoodModel(conn);

FoodBean food= fd.findFoodById(foodID);

//判断购物车是否放东西(第一次点餐)

if(cart.isEmpty()){

CartItemBean cartBean= new CartItemBean(food, 1);

cart.put(foodID, cartBean);

} else{

//判断当前菜是否在购物车中,false表示当前菜没有被点过。。

boolean flag= false;

//得到键的集合

Set set= cart.keySet();

//遍历集合

Object[] obj= set.toArray();

for(int i= 0; i< obj.length; i++){

Object object= obj[i];

//如果购物车已经存在当前菜,数量+1

if(object.equals(foodID)){

int quantity=((CartItemBean) cart.get(object))

.getQuantity();

quantity+= 1;

System.out.println(quantity);

((CartItemBean) cart.get(object)).setQuantity(quantity);

flag= true;

break;

}

}

if(flag== false){

//把当前菜放到购物车里面

CartItemBean cartBean= new CartItemBean(food, 1);

cart.put(foodID, cartBean);

}

}

return cart;

}

/**

*取消订餐

*/

public Map remove(Map cart, String foodID){

cart.remove(foodID);

return cart;

}

/**

*更新购物车信息

*

*@param cart

*@param foodID

*@return

*/

public Map<String, CartItemBean> update(Map cart, String foodID,

boolean isAddorRemove){

Map map;

if(isAddorRemove){

map= add(cart, foodID);

} else{

map= remove(cart, foodID);

}

return map;

}

}

好了,关于购物车代码html和html购物车页面代码的问题到这里结束啦,希望可以解决您的问题哈!

恒常机关之心?恒常机关之心哪些角色需要colspan代码表示什么, colspan的用法