Javaweb制定的订餐系统+jsp+servlet+Java+MySQL

订餐系统结构

Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第1张图片

  1. 登录界面
  2. Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第2张图片
  3. 商品界面
  4. Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第3张图片
  5. 详细商品界面
  6. Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第4张图片
  7. 购物车列表界面
  8. Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第5张图片
  9. 下单界面
    10.Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第6张图片
  10. 订单成功界面
  11. Javaweb制定的订餐系统+jsp+servlet+Java+MySQL_第7张图片
package com.orderonline.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 * @author yangxiaoqiang
 * 
 * */
/**数据库连接类*/
public class DBUtil {

	private static final String CLASSNAME = "com.mysql.jdbc.Driver";
	private static final String URL = "jdbc:mysql://localhost:3306/food_db?characterEncoding=utf-8&serverTimezone=GMT";
	private static final String USERNAME = "root";
	private static final String PASSWORD = "443650890";

	static {
		try {
			Class.forName(CLASSNAME);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void closeAll(Connection conn, PreparedStatement pstmt, ResultSet rs) {
		try {
			if (rs != null) {
				rs.close();
			}
			if (pstmt != null) {
				pstmt.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}

package com.orderonline.info.user;

import com.orderonline.pojo.TBOrder;
import com.orderonline.pojo.TbCate;
import com.orderonline.pojo.TbUser;
import com.orderonline.pojo.Tborder_detail;
/**
 * @author yangxiaoqiang
 * 
 * */
/**操作接口--查询和检查用户信息是否存在*/
public interface User_Cart_Imp {
	/**通过user_id找到用户信息-----针对页面details.jsp and shopCart.jsp**/
	public TbUser userInfo(Integer user_id);
	/**通过cart_id找到该商品信息-----针对页面details.jsp  and shopCart.jsp*/
	public TbCate cartInfo(Integer cart_id);
	
	
	/**通过order_id找到用户是否存相同订单id*/
	public boolean ordercheck(Integer order_id);
	
	/**通过order_id找到用户是否存相同订单id*/
	public TBOrder order(Integer order_id);
	
	/**查出用户下的所有下单信息*/
	public TBOrder orderinfo(Integer user_id);
	
	
	
	/**订单信息表*/
	public int InsertOrder(TBOrder Order);
	
	/**购物车信息添加——订单详细信息表*/
	public int InsertTborder_detail(Integer order_id,Tborder_detail detail);
}

package com.orderonline.info.user;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.orderonline.db.DBUtil;
import com.orderonline.pojo.TBOrder;
import com.orderonline.pojo.TbCate;
import com.orderonline.pojo.TbUser;
import com.orderonline.pojo.Tborder_detail;

/**
 * @author yangxiaoqiang
 * 
 * */
/**实现操作类--查询和检查用户信息是否存在*/
public class user_cart_info implements User_Cart_Imp {

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	@Override
	public TbUser userInfo(Integer user_id) {
		TbUser user = null;
		String sql = "select * from tb_user where user_id=? ";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, user_id);
			rs = pstmt.executeQuery();
			if (rs.next()) {// 当登录成功
				user = new TbUser();
				user.setUser_id(rs.getInt("user_id"));
				user.setUser_name(rs.getString("user_name"));
				user.setCh_name(rs.getString("ch_name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return user;
	}

	@Override
	public TbCate cartInfo(Integer cart_id) {
		TbCate cate=new TbCate();
		String sql="select * from tb_cate where cate_id=? ";
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, cart_id);
			// 执行SQL语句
			rs = pstmt.executeQuery();
			while(rs.next()) {
				cate = new TbCate();
				cate.setCate_id(rs.getInt("cate_id"));
				cate.setCate_name(rs.getString("cate_name"));
				cate.setCur_price(rs.getFloat("cur_price"));
				cate.setDescript(rs.getString("descript"));
				cate.setImg_path(rs.getString("img_path"));
				cate.setOri_price(rs.getFloat("ori_price"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return cate;
	}

	@Override
	public boolean ordercheck(Integer order_id) {
		String sql = "select * from tb_order where order_id=? ";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, order_id);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				return true;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return false;
	}
	
	
	
	@Override
	public TBOrder orderinfo(Integer user_id) {
		TBOrder Order = new TBOrder() ;
		String sql = "select * from tb_order where user_id=? ";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, user_id);
			rs = pstmt.executeQuery();
			if(rs.next()) {
				Order.setOrder_id(rs.getInt("order_id"));
				Order.setAddress(rs.getString("address"));
				Order.setCh_name(rs.getString("ch_name"));
				Order.setEmail(rs.getString("email"));
				Order.setMobile(rs.getString("mobile"));
				Order.setPayType(rs.getString("payType"));
				Order.setPhone(rs.getString("phone"));
				Order.setPostalcode(rs.getString("postalcode"));
				Order.setPostscript(rs.getString("postscript"));
				Order.setSendType(rs.getString("sendType"));
				Order.setUser_id(rs.getInt("user_id"));
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return Order;
	}
	
	
		//测试成功!
	public static void main(String[] args){
		//System.out.println(new user_cart_info().ordercheck(1));
		//System.out.println(new user_cart_info().userInfo(1));
		//System.out.println(new user_cart_info().cartInfo(1));
		//System.out.println(new user_cart_info().orderinfo(1));
	/*	TBOrder Order=new TBOrder();
		Order.setAddress("sadf");
		Order.setCh_name("556300");
		Order.setEmail("556300");
		Order.setMobile("556300");
		Order.setOrder_id(456);
		Order.setPayType("d");
		Order.setPhone("556300");
		Order.setPostalcode("556300");
		Order.setPostscript("不好");
		Order.setSendType("s");
		Order.setUser_id(1);
		int i=new user_cart_info().InsertOrder(Order);
		System.out.println(i);
		*/
		/*Tborder_detail detail=new Tborder_detail();
		detail.setCate_id(1);
		detail.setCate_name("fas");
		detail.setCOUNT(5);
		detail.setDetail_id(1);
		detail.setMoney(22);
		detail.setPrice(55);
		detail.setOrder_id(1);
		
		int i=new user_cart_info().InsertTborder_detail(1, detail);
		System.out.println(i);
		*/
	}

	

	@Override
	public int InsertTborder_detail(Integer order_id, Tborder_detail detail) {
		String sql = "insert into tb_order_detail values (?,?,?,?,?,?,?) ";
		conn = DBUtil.getConnection();
		int count = 0; // 受影响的行数
		try {
			pstmt = (PreparedStatement) conn.prepareStatement(sql);
			// 设置参数
			pstmt.setObject(1,0 );
			pstmt.setObject(2,order_id );
			pstmt.setObject(3, detail.getCate_id());
			pstmt.setObject(4, detail.getCate_name());
			pstmt.setObject(5, detail.getPrice());
			pstmt.setObject(6, detail.getCOUNT());
			pstmt.setObject(7, detail.getMoney());
			count = pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		return count;
	}

	@Override
	public int InsertOrder(TBOrder Order) {
		String sql = "insert into tb_order VALUES(?,?,?,?,?,?,?,?,?,?,?) ";
		conn = DBUtil.getConnection();
		int count = 0; // 受影响的行数
		try {
			pstmt = (PreparedStatement) conn.prepareStatement(sql);
			// 设置参数
			pstmt.setObject(1,Order.getOrder_id() );
			pstmt.setObject(2,Order.getUser_id() );
			pstmt.setObject(3, Order.getCh_name());
			pstmt.setObject(4, Order.getAddress());
			pstmt.setObject(5, Order.getPostalcode());
			pstmt.setObject(6, Order.getPhone());
			pstmt.setObject(7, Order.getMobile());
			pstmt.setObject(8, Order.getEmail());
			pstmt.setObject(9, Order.getSendType());
			pstmt.setObject(10, Order.getPayType());
			pstmt.setObject(11, Order.getPostscript());
			count = pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		return count;
	}

	@Override
	public TBOrder order(Integer order_id) {
		TBOrder Order = null ;
		String sql = "select * from tb_order where order_id=?  ;";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setObject(1, order_id);
			rs = pstmt.executeQuery();
			if (rs.next()) {// 当登录成功
				Order = new TBOrder();
				Order.setCh_name(rs.getString("ch_name"));
				Order.setAddress(rs.getString("address"));
				Order.setPhone(rs.getString("phone"));
				Order.setEmail(rs.getString("email"));
				Order.setOrder_id(rs.getInt("order_id"));
				Order.setMobile(rs.getString("mobile"));
				Order.setPostscript(rs.getString("postscript"));
				Order.setSendType(rs.getString("sendType"));
				Order.setPostalcode(rs.getString("postalcode"));
				Order.setPayType(rs.getString("payType"));;
				
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return Order;
	}
	
	
	
}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/***商品信息类*/
public class TbCate {
	
	private Integer cate_id;
	private String cate_name;
	private Float ori_price;
	private Float cur_price;
	private String img_path;
	private String descript;
	public Integer getCate_id() {
		return cate_id;
	}
	public void setCate_id(Integer cate_id) {
		this.cate_id = cate_id;
	}
	public String getCate_name() {
		return cate_name;
	}
	public void setCate_name(String cate_name) {
		this.cate_name = cate_name;
	}
	public Float getOri_price() {
		return ori_price;
	}
	public void setOri_price(Float ori_price) {
		this.ori_price = ori_price;
	}
	public Float getCur_price() {
		return cur_price;
	}
	public void setCur_price(Float cur_price) {
		this.cur_price = cur_price;
	}
	public String getImg_path() {
		return img_path;
	}
	public void setImg_path(String img_path) {
		this.img_path = img_path;
	}
	public String getDescript() {
		return descript;
	}
	public void setDescript(String descript) {
		this.descript = descript;
	}
	public TbCate(Integer cate_id, String cate_name, Float ori_price, Float cur_price, String img_path,
			String descript) {
		this.cate_id = cate_id;
		this.cate_name = cate_name;
		this.ori_price = ori_price;
		this.cur_price = cur_price;
		this.img_path = img_path;
		this.descript = descript;
	}
	
	public TbCate() {
	}
	@Override
	public String toString() {
		return "TbCate [cate_id=" + cate_id + ", cate_name=" + cate_name + ", ori_price=" + ori_price + ", cur_price="
				+ cur_price + ", img_path=" + img_path + ", descript=" + descript + "]";
	}
	

}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/**订单详细信息表--类*/
public class Tborder_detail {
	 private Integer detail_id ; // '订单详细id',
	 private Integer  order_id ;// '订单id' ,
	 private Integer   cate_id  ;//'商品id',
	 private String  cate_name  ; //'商品名称',
	 private double  price   ;//'价格',
	 private Integer  COUNT ; //'数量',
	 private double  money   ;// '金额'
	public Integer getDetail_id() {
		return detail_id;
	}
	public void setDetail_id(Integer detail_id) {
		this.detail_id = detail_id;
	}
	public Integer getOrder_id() {
		return order_id;
	}
	public void setOrder_id(Integer order_id) {
		this.order_id = order_id;
	}
	public Integer getCate_id() {
		return cate_id;
	}
	public void setCate_id(Integer cate_id) {
		this.cate_id = cate_id;
	}
	public String getCate_name() {
		return cate_name;
	}
	public void setCate_name(String cate_name) {
		this.cate_name = cate_name;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public Integer getCOUNT() {
		return COUNT;
	}
	public void setCOUNT(Integer cOUNT) {
		COUNT = cOUNT;
	}
	public double getMoney() {
		return money;
	}
	public void setMoney(double money) {
		this.money = money;
	}
	public Tborder_detail() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Tborder_detail(Integer detail_id, Integer order_id, Integer cate_id,
			String cate_name, Float price, Integer cOUNT, Float money) {
		super();
		this.detail_id = detail_id;
		this.order_id = order_id;
		this.cate_id = cate_id;
		this.cate_name = cate_name;
		this.price = price;
		COUNT = cOUNT;
		this.money = money;
	}
	@Override
	public String toString() {
		return "Tborder_detail [detail_id=" + detail_id + ", order_id="
				+ order_id + ", cate_id=" + cate_id + ", cate_name="
				+ cate_name + ", price=" + price + ", COUNT=" + COUNT
				+ ", money=" + money + "]";
	}
	 
	 
}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/**订单类*/
public class TBOrder {
	private Integer order_id; // '订单id',
    private Integer user_id ;//'用户id',
	private String  ch_name ; // '订餐人',
	private String  address ;// '送货地址',
	private String  postalcode ;// '邮政编码',
	private String  phone   ; //'联系电话',				
	private String   mobile   ; // '移动电话',
	private String  email   ; //'电子邮件',
	private String  sendType ; // '配送方式',
	private String  payType  ; // '支付方式',
	private String  postscript ;  //'订单附言'
	public Integer getOrder_id() {
		return order_id;
	}
	public void setOrder_id(Integer order_id) {
		this.order_id = order_id;
	}
	public Integer getUser_id() {
		return user_id;
	}
	public void setUser_id(Integer user_id) {
		this.user_id = user_id;
	}
	public String getCh_name() {
		return ch_name;
	}
	public void setCh_name(String ch_name) {
		this.ch_name = ch_name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPostalcode() {
		return postalcode;
	}
	public void setPostalcode(String postalcode) {
		this.postalcode = postalcode;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getSendType() {
		return sendType;
	}
	public void setSendType(String sendType) {
		this.sendType = sendType;
	}
	public String getPayType() {
		return payType;
	}
	public void setPayType(String payType) {
		this.payType = payType;
	}
	public String getPostscript() {
		return postscript;
	}
	public void setPostscript(String postscript) {
		this.postscript = postscript;
	}
	public TBOrder() {
		
	}
	public TBOrder(Integer order_id, Integer user_id, String ch_name,
			String address, String postalcode, String phone, String mobile,
			String email, String sendType, String payType, String postscript) {
		super();
		this.order_id = order_id;
		this.user_id = user_id;
		this.ch_name = ch_name;
		this.address = address;
		this.postalcode = postalcode;
		this.phone = phone;
		this.mobile = mobile;
		this.email = email;
		this.sendType = sendType;
		this.payType = payType;
		this.postscript = postscript;
	}
	@Override
	public String toString() {
		return "TBOrder [order_id=" + order_id + ", user_id=" + user_id
				+ ", ch_name=" + ch_name + ", address=" + address
				+ ", postalcode=" + postalcode + ", phone=" + phone
				+ ", mobile=" + mobile + ", email=" + email + ", sendType="
				+ sendType + ", payType=" + payType + ", postscript="
				+ postscript + "]";
	}
	
	

}

package com.orderonline.pojo;
/**
 * @author yangxiaoqiang
 * 
 * */
/**用户表信息类*/
public class TbUser {

	private Integer user_id; // 用户ID
	private String user_name; // 用户名称
	private String ch_name; // 真实姓名
	private String password; // 用户密码

	public Integer getUser_id() {
		return user_id;
	}

	public void setUser_id(Integer user_id) {
		this.user_id = user_id;
	}

	public String getUser_name() {
		return user_name;
	}

	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}

	public String getCh_name() {
		return ch_name;
	}

	public void setCh_name(String ch_name) {
		this.ch_name = ch_name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public TbUser(Integer user_id, String user_name, String ch_name, String password) {
		this.user_id = user_id;
		this.user_name = user_name;
		this.ch_name = ch_name;
		this.password = password;
	}

	public TbUser() {
	}

	@Override
	public String toString() {
		return "TbUser [user_id=" + user_id + ", user_name=" + user_name + ", ch_name=" + ch_name + ", password="
				+ password + "]";
	}

}

package com.orderonline.service.cate;

import java.util.List;

import com.orderonline.pojo.TbCate;

public interface TbCateService {
	
	public List cateList();

}

package com.orderonline.service.cate;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.orderonline.db.DBUtil;
import com.orderonline.pojo.TbCate;

public class TbCateServiceImpl implements TbCateService {

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	
	@Override
	public List cateList() {
		List list = new ArrayList();
		TbCate cate = null;
		String sql = "select * from tb_cate";
		
		conn = DBUtil.getConnection();
		
		try {
			pstmt = conn.prepareStatement(sql);
			// 执行SQL语句
			rs = pstmt.executeQuery();
			while(rs.next()) {
				cate = new TbCate();
				
				cate.setCate_id(rs.getInt("cate_id"));
				cate.setCate_name(rs.getString("cate_name"));
				cate.setCur_price(rs.getFloat("cur_price"));
				cate.setDescript(rs.getString("descript"));
				cate.setImg_path(rs.getString("img_path"));
				cate.setOri_price(rs.getFloat("ori_price"));
				list.add(cate);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		return list;
	}
	/*
	//测试两个商品一行
	public static void main(String[] args) {
		TbCateService tcs = new TbCateServiceImpl();
		Iterator it = tcs.cateList().iterator();
		// 3,4,5,6,7,8,9,10
		while(it.hasNext()) { // 判断迭代器里是否还有值存在
			TbCate t1 = it.next();
			System.out.print(t1.getCate_name() + "\t");
			//第二个商品
			if (it.hasNext()) {
				TbCate t2 = it.next();
				System.out.print(t2.getCate_name());
			}
			
			System.out.println("\n");
		}
		
		
	}*/

}

package com.orderonline.service.user;

import com.orderonline.pojo.TbUser;

public interface TbUserService {
	
	public TbUser userLogin(String user,String pass);

}

package com.orderonline.service.user;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.orderonline.db.DBUtil;
import com.orderonline.pojo.TbUser;

public class TbUserServiceImpl implements TbUserService {

	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	
	@Override
	public TbUser userLogin(String username, String pass) {
		TbUser user = null;
		String sql = "select * from tb_user where user_name=? and password=?";
		// 获取数据库链接
		conn = DBUtil.getConnection();
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, username);
			pstmt.setString(2, pass);
			rs = pstmt.executeQuery();
			if (rs.next()) {// 当登录成功
				user = new TbUser();
				user.setUser_id(rs.getInt("user_id"));
				user.setUser_name(rs.getString("user_name"));
				user.setCh_name(rs.getString("ch_name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeAll(conn, pstmt, rs);
		}
		
		return user;
	}
	
	/*public static void main(String[] args) {
		TbUserService ts = new TbUserServiceImpl();
		TbUser user = ts.userLogin("test", "test");
		System.out.println(user);
	}
*/
}

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.orderonline.service.user.*,java.util.ArrayList,java.util.HashMap" %>
<%@ page import="com.orderonline.service.cate.*" %>
<%@ page import="com.orderonline.pojo.TbUser"%>
<%@ page import="com.orderonline.pojo.TbCate"%>
<%@ page import="com.orderonline.pojo.Tborder_detail" %>
<%@ page import="com.orderonline.info.user.User_Cart_Imp"%>
<%@ page import="com.orderonline.info.user.user_cart_info"%>
<%@page import="java.io.UnsupportedEncodingException"%>
<%@ page import="java.util.*"%>
<%
	request.setCharacterEncoding("utf-8");
	String monsh = request.getParameter("monsh");
	
	String loginName = request.getParameter("loginName");
	String loginPass = request.getParameter("loginPass");
	

	TbCateService tcs = new TbCateServiceImpl();
	if (null != loginName && null != loginPass){// 登录成功
		TbUserService ts = new TbUserServiceImpl();
		TbUser user = ts.userLogin(loginName, loginPass);
		//封装购物车容器
		if(null != user){
		HashMap Shoplist = new HashMap();//包装袋
		
		application.setAttribute("Shoplist",Shoplist); //加入购入表单存放application区域
		session.setAttribute("user", user);
		// 登录成功后查询所有商品信息
		List cateList = tcs.cateList();
		request.setAttribute("cateList", cateList);
		request.getRequestDispatcher("../show.jsp").forward(request, response);
		//response.sendRedirect("../show.jsp");
		
		}
		out.println("");
		
	}else if(monsh.equals("shopTool") || monsh.equals("details")){//details页面回来的商品详细信息添加
		Integer userId = Integer.parseInt(request.getParameter("D_userId"));
		Integer cate_Id = Integer.parseInt(request.getParameter("D_cateId"));
		User_Cart_Imp users=new user_cart_info();
		TbUser 	user1=(TbUser)users.userInfo(userId);
		User_Cart_Imp cart_Info=new user_cart_info();
		TbCate tbcate=(TbCate)cart_Info.cartInfo(cate_Id);
		
		Integer cate_ids=tbcate.getCate_id();
		String cate_name=tbcate.getCate_name();
		double	newPrice=tbcate.getCur_price();
	   // double	oldPrice=tbcate.getOri_price();
	    //String descript=tbcate.getDescript();
	    //String imgs=tbcate.getImg_path();
		if(cate_Id != null){
								//获取购物商品信息
				HashMap mp =(HashMap)application.getAttribute("Shoplist");
							
							Tborder_detail detail=null;
							try {

								if (mp.containsKey(cate_Id)) {// containsKey()
									 detail =(Tborder_detail) mp.get(cate_Id);
									detail.setPrice((double)newPrice);
									int cOUNTs=detail.getCOUNT()+1;
									detail.setCOUNT(cOUNTs);
									detail.setMoney(cOUNTs*(double)newPrice);
								} else {
									detail=new Tborder_detail();
									detail.setDetail_id(0);
									detail.setCate_id(cate_Id);
									detail.setCate_name(cate_name);
									detail.setCOUNT(1);
									detail.setMoney((double)newPrice);
									detail.setPrice((double)newPrice);
									
									
								}
								mp.put(cate_Id, detail);//集合里加商品
								application.setAttribute("Shoplist",mp); //加入购入的商品存放application区域
								
							} catch (NullPointerException e) {
								System.out.println("NullPointerException---login_verify.jsp页面"+e);
							}
		}
							session.setAttribute("user", user1);
							
					List cateList = tcs.cateList();
					request.setAttribute("cateList", cateList);
					request.getRequestDispatcher("../show.jsp").forward(request, response);
		}
	else if( monsh.equals("shopCart"))
	{		//details页面回来的商品详细信息添加
						List cateList = tcs.cateList();
						request.setAttribute("cateList", cateList);
						request.getRequestDispatcher("../show.jsp").forward(request, response);
	}
	else if( monsh.equals("center"))
	{		//details页面回来的商品详细信息添加
			Integer userId = Integer.parseInt(request.getParameter("D_userId"));
						request.getRequestDispatcher("../checkOut.jsp").forward(request, response);
	}
	else if( monsh.equals("checkOut"))
	{		//details页面回来的商品详细信息添加
		//System.out.println("我的id="+request.getParameter("or_id"));
		Integer or_id = Integer.parseInt(request.getParameter("or_id"));
		request.setAttribute("or_id", or_id);
						request.getRequestDispatcher("../seeYou.jsp").forward(request, response);
	}
	else if(monsh.equals("shopCartclean"))
	{		//details页面回来的商品详细信息添加
		application.removeAttribute("Shoplist");//移除商品
		
		//从新创建购物车
		HashMap Shoplist = new HashMap();//包装袋
		
		application.setAttribute("Shoplist",Shoplist); //加入购入表单存放application区域
		
		
			Integer userId = Integer.parseInt(request.getParameter("D_userId"));
			User_Cart_Imp users=new user_cart_info();
			TbUser 	user1=(TbUser)users.userInfo(userId);
						List cateList = tcs.cateList();
						request.setAttribute("cateList", cateList);
						request.getRequestDispatcher("../show.jsp").forward(request, response);
			}
	
	
	out.println("");
	
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>

<%
			request.setCharacterEncoding("utf-8");
			
			String basePath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
		String userid=	request.getParameter("D_userId");
		String Shopid=  request.getParameter("D_cateId");
			
		if(userid !=null && Shopid !=null ){	
			Integer userId = Integer.parseInt(userid);
			Integer cate_Id = Integer.parseInt(Shopid);
			%>
			
<%}
		out.println("");

%>
		
		


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
    <% 
String basePath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();

%>




我学我会网上订餐系统








 
      我学我会 网上订餐系统
 
 | 网站首页 | 关于我们 | 定餐帮助 | 网上定餐 | 客服中心 | 
 
 
 
 
欢迎您使用我学我会网上订餐系统,祝您用餐愉快!
  

请确认支付和配送信息
订 餐 人:
送货地址:
邮政编码:
联系电话:
移动电话:
电子邮件:
配送方式:
 送餐上门  10元起送
支付方式:
 餐到付款  仅限3环内
订单附言:

Copyright © 2015     益阳职业技术学院-软件学院 所有



<%@page import="java.io.UnsupportedEncodingException"%>
<%@page import="com.orderonline.info.user.User_Cart_Imp"%>
<%@page import="com.orderonline.info.user.user_cart_info"%>
<%@page import="com.orderonline.pojo.TbCate" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
  




我学我会网上订餐系统


<%!

	//转字符集乱码私有方法
private String myString(String value) {
	byte[] bt;
	String str=null;
	try {
		bt = value.getBytes("ISO-8859-1");
		 str=new String(bt,"UTF-8");
	} catch (UnsupportedEncodingException e) {
		
		e.printStackTrace();
	}
	
	return str;
}
%>
<%      String basePath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
		
		String user_id= this.myString(request.getParameter("user_id"));//用户id
		String cate_id= this.myString(request.getParameter("cate_id"));//商品id
		if(user_id != null && cate_id != null){
		int userId = Integer.parseInt( user_id ); 
		int cate_Id = Integer.parseInt( cate_id ); 
		
		User_Cart_Imp cart_Info=new user_cart_info();
		TbCate tbcate=(TbCate)cart_Info.cartInfo(cate_Id);
		
		Integer cate_ids=tbcate.getCate_id();
		String cate_name=tbcate.getCate_name();
		double	newPrice=tbcate.getCur_price();
	    double	oldPrice=tbcate.getOri_price();
	    String descript=tbcate.getDescript();
	    String imgs=tbcate.getImg_path();
%>

<%


%>




 
      我学我会 网上订餐系统
 
 | 网站首页 | 关于我们 | 定餐帮助 | 网上定餐 | 客服中心 | 
 
 
 
 
欢迎您使用我学我会网上订餐系统,祝您用餐愉快!
  
我学我会网上点餐系统用户请直接登录

<%=cate_name %>
原价:人民币<%=oldPrice %>元
现价:人民币<%=newPrice %>元
<%=descript %>
编号: <%=cate_Id %>

详细资料


<%=descript %>



Copyright © 2015     益阳职业技术学院-软件学院 所有

 



<%} %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>




我学我会网上订餐系统







 
      我学我会 网上订餐系统
 
 | 网站首页 | 关于我们 | 定餐帮助 | 网上定餐 | 客服中心 | 
 
 
 
 
欢迎您使用我学我会网上订餐系统,祝您用餐愉快!
  
我学我会网上点餐系统用户请直接登录

       
  用户名:  
  密  码:  
   
       

Copyright © 2015     益阳职业技术学院-软件学院 所有

 



<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.orderonline.pojo.TbUser"%>
<%@page import="com.orderonline.info.user.User_Cart_Imp"%>
<%@page import="com.orderonline.info.user.user_cart_info"%>
<%@page import="com.orderonline.pojo.TBOrder"%>
<%@page import="com.orderonline.pojo.Tborder_detail"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
      <% 
String basePath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();

%>




我学我会网上订餐系统







 
      我学我会 网上订餐系统
 
 | 网站首页 | 关于我们 | 定餐帮助 | 网上定餐 | 客服中心 | 
 
 
 
 
欢迎您使用我学我会网上订餐系统,祝您用餐愉快!
  
我学我会网上点餐系统用户请直接登录

<% Integer or_id=null; TBOrder order=null; TbUser user = (TbUser)session.getAttribute("user"); //System.out.println(user); // System.out.println("============"+request.getAttribute("or_id").toString()); if((request.getAttribute("or_id")) != null){ or_id = Integer.parseInt(request.getAttribute("or_id").toString()); User_Cart_Imp or_info=new user_cart_info(); order=or_info.order(or_id); //System.out.println(order+"555555555555555555555555555555555555555"+or_info.ordercheck(or_id)); } HashMap mp2 =(HashMap)application.getAttribute("Shoplist"); Double sum=0.0; Iterator iter = mp2.keySet().iterator(); while (iter.hasNext()) { Integer key = (Integer)iter.next(); Tborder_detail val = (Tborder_detail)mp2.get(key); //已经选好的商品 Integer Cate_id=val.getCate_id(); String Cate_name= val.getCate_name(); Integer COUNTs=val.getCOUNT(); double Price= val.getPrice(); sum+=(COUNTs)*Price; } %>
用户名: <%=user.getUser_name() %>          订单号:<%=order.getOrder_id() %> 联系号码:<%=order.getPhone() %> 
 00000000 感谢您的惠顾祝您用餐愉快!  邮编:<%=order.getPostalcode() %>
 姓名: <%=order.getCh_name() %>  支付方式:餐到付款
  收获地址:<%=order.getAddress() %> 配上送方式:送餐上门 
本次消费 <%=sum %> ¥          签收人签名:    <% SimpleDateFormat df = new SimpleDateFormat("产生时间:yyyy-MM-dd"); out.println(df.format(new Date())); %>

Copyright © 2015     益阳职业技术学院-软件学院 所有

 



<%@page import="com.orderonline.pojo.TBOrder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.orderonline.service.user.*,java.util.ArrayList,java.util.HashMap,java.util.Iterator" %>
<%@ page import="com.orderonline.service.cate.*" %>
<%@ page import="com.orderonline.pojo.TbUser"%>
<%@ page import="com.orderonline.pojo.TbCate"%>
<%@ page import="com.orderonline.pojo.Tborder_detail" %>
<%@page import="java.io.UnsupportedEncodingException"%>
<%@page import="com.orderonline.info.user.User_Cart_Imp"%>
<%@page import="com.orderonline.info.user.user_cart_info"%>
<%@page import="com.orderonline.pojo.TbCate" %>
<%@ page import="java.util.*"%>
<%     request.setCharacterEncoding("utf-8");

String basePath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();

%>


购物车




<% 
	String monsh=request.getParameter("monsh");
		//System.out.println(monsh);
	if(monsh !=null){
	if(monsh.equals("checkOut")){
		
		TbUser user = (TbUser)session.getAttribute("user");
		Integer or_user_id=(Integer)user.getUser_id();
		String name=request.getParameter("name");
		String addr=request.getParameter("addr");
		String zip=request.getParameter("zip");
		String tel=request.getParameter("tel");
		String mov=request.getParameter("mov");
		String email=request.getParameter("email");
		String sendradio=request.getParameter("sendradio");
		String payradio=request.getParameter("payradio");
		String bz=request.getParameter("bz");
		//下单前检查购物车是否有商品
		
	if(((HashMap)application.getAttribute("Shoplist")).size()>0){
		User_Cart_Imp o_c_insert=new user_cart_info();
		Integer or_id=(int)Math.round(Math.random()*Integer.MAX_VALUE);
		while(o_c_insert.ordercheck(or_id)){
			or_id=(int)Math.round(Math.random()*Integer.MAX_VALUE);
		}
		TBOrder Order=new TBOrder();
		Order.setAddress(addr);
		Order.setCh_name(name);
		Order.setEmail(email);
		Order.setMobile(mov);
		Order.setOrder_id(or_id);
		Order.setPayType(payradio);
		Order.setPhone(tel);
		Order.setPostalcode(zip);
		Order.setPostscript(bz);
		Order.setSendType(sendradio);
		Order.setUser_id(or_user_id);
		int i=o_c_insert.InsertOrder(Order);
		
		if(i>0){
			HashMap mp3 =(HashMap)application.getAttribute("Shoplist");
			Double sumss=0.0;
			Iterator iter1 = mp3.keySet().iterator();
			int j=0;
			while (iter1.hasNext()) {
				try{
				Integer key = (Integer)iter1.next();
					Tborder_detail val11 = (Tborder_detail)mp3.get(key);
					//已经选好的商品
					
					 Integer Cate_id=val11.getCate_id();
					 String Cate_name= val11.getCate_name();
					 Integer COUNTs=val11.getCOUNT();
					double Price= val11.getPrice();
					sumss+=(COUNTs)*Price;
					

					Tborder_detail detail11=new Tborder_detail();
					detail11.setCate_id(Cate_id);
					detail11.setCate_name(Cate_name);
					detail11.setCOUNT(COUNTs);
					detail11.setDetail_id(0);
					detail11.setMoney(COUNTs*Price);
					detail11.setPrice(Price);
					//detail11.setOrder_id(or_id);
					 j+=new user_cart_info().InsertTborder_detail(or_id, detail11);
					
				 }catch(NullPointerException e){
						System.out.println("NullPointerException-------shopCart.jsp页面");
				}
			
			
			if(j>0){
			
				out.print("");
				//application.removeAttribute("Shoplist");//下单成功-移除当前下单的商品
				//从新创建购物车
				//HashMap Shoplist = new HashMap();//包装袋
				//application.setAttribute("Shoplist",Shoplist); //加入购入表单存放application区域
				%>
				
			<%}
			}
		}
	}else{%>

	

<% }
  }
	
	
	
}%>




<% 
TbUser user11 = (TbUser)session.getAttribute("user");
Integer user_id12=(Integer)user11.getUser_id();
Integer  user_id=user_id12;
if(request.getParameter("user_id") !=null ){
  user_id=Integer.parseInt(request.getParameter("user_id")) ;//用户id 
  }%>


您的购物车中有以下商品
<% HashMap mp2 =(HashMap)application.getAttribute("Shoplist"); Double sum=0.0; Iterator iter = mp2.keySet().iterator(); while (iter.hasNext()) { Integer key = (Integer)iter.next(); Tborder_detail val = (Tborder_detail)mp2.get(key); //已经选好的商品 Integer Cate_id=val.getCate_id(); String Cate_name= val.getCate_name(); Integer COUNTs=val.getCOUNT(); double Price= val.getPrice(); sum+=(COUNTs)*Price; /* Integer Cate_id=56456; String Cate_name= "张三"; Integer COUNT=55; double Price= 44.0; */ %> <% }%>
编号
商品名称
单价
数量
金额
<%=Cate_id %> <%=Cate_name %> ¥<%=Price %> <%=COUNTs %> ¥<%=Price*COUNTs %>
合计 - - - ¥<%=sum %>

清空购物车 继续购物 生成订单

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<%@ page import="com.orderonline.pojo.TbUser"%>
<%@ page import="com.orderonline.pojo.TbCate"%>


<%
	TbUser user = (TbUser)session.getAttribute("user");
	List cateList = (List)request.getAttribute("cateList");
	
	String basePath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
	//System.out.println(basePath);
	
%>


我学我会网上订餐系统







 
      我学我会 网上订餐系统
 
当前用户:<%=user.getUser_name() %>  | 网站首页 | 关于我们 | 定餐帮助 | 网上定餐 | 客服中心 | 
 
 
 
 
欢迎您使用我学我会网上订餐系统,祝您用餐愉快!
  

<% Iterator it = cateList.iterator(); while(it.hasNext()){ TbCate t1 = it.next(); %> <% if (it.hasNext()){ TbCate t2 = it.next(); %> <% } %> <% } %>
点击图片查看内容
<%=t1.getCate_name() %>
现价:人民币<%=t1.getCur_price() %>元
<%=t1.getDescript() %>
编号: <%=t1.getCate_id() %>
点击图片查看内容
<%=t2.getCate_name() %>
现价:人民币<%=t2.getCur_price() %>元
<%=t2.getDescript() %>
编号: <%=t2.getCate_id() %>

Copyright © 2015     益阳职业技术学院-软件学院 所有

 



数据库表




create database food_db;

/*==============================================================*/
/* Table: tb_cate 商品信息表*/
/*==============================================================*/
create table tb_cate (
   cate_id              int  primary key auto_increment not null,
   cate_name            varchar(50)          not null,
   ori_price            float                null,
   cur_price            float                not null,
   img_path             varchar(50)          not null,
   descript             text                 null
);

/*==============================================================*/
/* Table: tb_order      订单表                                        */
/*==============================================================*/
create table tb_order (
   order_id             int primary key auto_increment not null,
   user_id              int                  null,
   ch_name              varchar(30)          not null,
   address              varchar(100)         null,
   postalcode           varchar(10)          null,
   phone                varchar(30)          null,
   mobile               varchar(30)          null,
   email                varchar(50)          null,
   sendType             char(3)              null default '0',
   payType              char(3)              null default '0',
   postscript           text                 null
);

/*==============================================================*/
/* Table: tb_order_detail     订单详细信息表                                  */
/*==============================================================*/
create table tb_order_detail (
   detail_id            int   primary key auto_increment not null ,
   order_id             int                  null,
   cate_id              int                  null,
   cate_name            varchar(50)          not null,
   price                float                not null,
   count                int                  not null,
   money                float                not null
);

/*==============================================================*/
/* Table: tb_user                用户表                               */
/*==============================================================*/
create table tb_user (
   user_id              int  primary key auto_increment not null,
   user_name            varchar(30)          not null,
   ch_name              varchar(30)          not null,
   password             varchar(30)          not null
);

alter table tb_order
   add constraint FK_TB_ORDER_REFERENCE_TB_USER foreign key (user_id)
      references tb_user (user_id);

alter table tb_order_detail
   add constraint FK_TB_ORDER_REFERENCE_TB_ORDER foreign key (order_id)
      references tb_order (order_id);

alter table tb_order_detail
   add constraint FK_TB_ORDER_REFERENCE_TB_CATE foreign key (cate_id)
      references tb_cate (cate_id);


-----------------------------------------------------------------------------------
insert into tb_user values(0,'test','路人甲','test');

insert into tb_cate values(0,'皮蛋瘦肉粥',5,5,'500047.jpg','美味可口!');
insert into tb_cate values(0,'清炒时蔬',5,5,'500046.jpg','时令绿色蔬菜!');
insert into tb_cate values(0,'炸酱面',8,8,'500045.jpg','京味小吃!');
insert into tb_cate values(0,'肉丝茄子',10,10,'500044.jpg','美味可口!');
insert into tb_cate values(0,'西红柿炒鸡蛋',6,6,'500043.jpg','经典搭配!');
insert into tb_cate values(0,'香油抄手',4,4,'500042.jpg','川味小吃,鲜香可口!');
insert into tb_cate values(0,'酸豆角炒肉末盖饭',8,8   ,'500041.jpg','开胃可口!');
insert into tb_cate values(0,'创意炒饭',7,7,'500038.jpg','原料:鸡蛋、胡萝卜、青豆。。。口味适中,非常爽口!');
insert into tb_cate values(0,'重庆小面',5,5,'500036.jpg','正宗重庆街头特色小面!');
insert into tb_cate values(0,'米粉汤',8,8,'500035.jpg','原料:米粉、骨头汤、豆腐、肉丸汤味鲜美,口感极佳!');
insert into tb_cate values(0,'特色炒饭',7,7,'500034.jpg','原料:蘑菇、鸡蛋、胡萝卜、青椒、绿色蔬菜。口感极好!');
insert into tb_cate values(0,'木须肉盖饭',8,8,'500033.jpg','原料:木耳、猪肉、青瓜、鸡蛋。口味适中,营养美味。');
insert into tb_cate values(0,'木须肉盖饭',8,8,'500026.jpg','原料:木耳、猪肉、青瓜、鸡蛋。口味清淡,美味营养。');
insert into tb_cate values(0,'西红柿打卤面',7,7,'500025.jpg','配料:西红柿、鸡蛋口味:清淡。');
insert into tb_cate values(0,'拉面',6,6,'500024.jpg','配料:牛肉、骨头汤口味:微辣、中辣、超辣。');
insert into tb_cate values(0,'刀削面',6,6,'500023.jpg','配料:青菜、猪肉、海带、骨头汤口味:微辣、中辣、超辣。');
insert into tb_cate values(0,'青菜肉丝粥',4,4,'500022.jpg','原料:青菜、肉丝口味清淡,清香可口!');
insert into tb_cate values(0,'土豆丝盖饭',7,7,'500008.jpg','好好吃哦');

你可能感兴趣的:(mysql,java,css,javascript,css3)