当前位置: 首页 > 编程日记 > 正文

Java项目:家居购物商城系统(java+html+jdbc+mysql)

源码获取:博客首页 "资源" 里下载!

一、项目简述

功能: Java Web精品项目源码,家居商城分类展示,商品展示, 商品下单,购物车,个人中心,后台管理,用户管理,商品管理,分类管理等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: Jdbc+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload

验证码控制器:

/*** 验证码*/
@WebServlet("/checkCodeServlet")
public class CheckCodeServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {//服务器通知浏览器不要缓存response.setHeader("pragma","no-cache");response.setHeader("cache-control","no-cache");response.setHeader("expires","0");//在内存中创建一个长80,宽30的图片,默认黑色背景//参数一:长//参数二:宽//参数三:颜色int width = 136;int height = 38;BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);//获取画笔Graphics g = image.getGraphics();//设置画笔颜色为灰色g.setColor(Color.GRAY);//填充图片g.fillRect(0,0, width,height);//产生4个随机验证码,12EyString checkCode = getCheckCode();//将验证码放入HttpSession中request.getSession().setAttribute("CHECKCODE_SERVER",checkCode);//设置画笔颜色为黄色g.setColor(Color.YELLOW);//设置字体的小大g.setFont(new Font("黑体",Font.BOLD,30));//向图片上写入验证码g.drawString(checkCode,36,28);//将内存中的图片输出到浏览器//参数一:图片对象//参数二:图片的格式,如PNG,JPG,GIF//参数三:图片输出到哪里去ImageIO.write(image,"PNG",response.getOutputStream());}/*** 产生4位随机字符串 */private String getCheckCode() {String base = "23456789ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz";int size = base.length();Random r = new Random();StringBuffer sb = new StringBuffer();for(int i=1;i<=4;i++){//产生0到size-1的随机值int index = r.nextInt(size);//在base字符串中获取下标为index的字符char c = base.charAt(index);//将c放入到StringBuffer中去sb.append(c);}return sb.toString();}public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request,response);}
}

用户信息服务:

@WebServlet("/toUserInfoServlet")
public class ToUserInfoServlet extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {HttpSession session = request.getSession();User user = (User) session.getAttribute("name");if (user != null) {UserService service = new UserServiceImpl();User newUser = service.findUserByUserId(user.getUser_id());CategoryService service1 = new CategoryServiceImpl();List<Category> flist = service1.findCategoryListByName("father");List<Category> clist = service1.findCategoryListByName("child");request.setAttribute("flist",flist);request.setAttribute("clist",clist);request.setAttribute("user",newUser);//查看该用户的各种订单数量OrderService service2 = new OrderServiceImpl();List<Order> orders = service2.findOrderByUserId(user.getUser_id());int a1 = 0;int a2 = 0;int a3 = 0;int a4 = 0;for (Order o:orders) {if ("0".equals(o.getIs_pay()) && "0".equals(o.getIs_ship()) && "0".equals(o.getIs_receipt())) {a1++;}if ("1".equals(o.getIs_pay()) && "0".equals(o.getIs_ship()) && "0".equals(o.getIs_receipt())) {a2++;}if ("1".equals(o.getIs_pay()) && "1".equals(o.getIs_ship()) && "0".equals(o.getIs_receipt())) {a3++;}if ("1".equals(o.getIs_pay()) && "1".equals(o.getIs_ship()) && "1".equals(o.getIs_receipt())) {a4++;}}request.setAttribute("a1",a1);request.setAttribute("a2",a2);request.setAttribute("a3",a3);request.setAttribute("a4",a4);request.getRequestDispatcher("mygxin.jsp").forward(request, response);}else {response.sendRedirect("login.jsp");}}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request,response);}
}

购物车数量信息:

@WebServlet("/selectProductList")
public class SelectProductList extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//查询购物车数量HttpSession session = request.getSession();User user = (User) session.getAttribute("name");String cartCount = "0";CartService service1 = new CartServiceImpl();if (user != null) {cartCount = String.valueOf(service1.findCartCountByUserId(user.getUser_id()));}else {cartCount = "?";}request.setAttribute("cartCount",cartCount);String cid = request.getParameter("cid");if (cid != null && !cid.trim().equals("")) {ProductService service = new ProductServiceImpl();List<Product> list = service.findProductByCategoryCid(Integer.valueOf(cid));request.setAttribute("productList",list);CategoryService service2 = new CategoryServiceImpl();Category c = service2.findCategoryByCid(Integer.valueOf(cid));System.out.println(c.getCategory_name());request.setAttribute("childC",c);Category f = service2.findCategoryByCid(c.getCategory_parentid());System.out.println(f.getCategory_name());request.setAttribute("fatherC",f);List<Category> flist =  service2.findCategoryListByName("father");request.setAttribute("flist", flist);List<Category> clist =  service2.findCategoryListByName("child");request.setAttribute("clist", clist);//没实现分类添加图片if (f.getCategory_id() == 1) {request.setAttribute("link", "images/temp/banner1.jpg");}else if (f.getCategory_id() == 2){request.setAttribute("link", "images/temp/bzbig.jpg");}else if (f.getCategory_id() == 3){request.setAttribute("link", "images/temp/banner2.jpg");}else if (f.getCategory_id() == 4){request.setAttribute("link", "images/temp/perfume_Banner.jpg");}else if (f.getCategory_id() == 5){request.setAttribute("link", "img/idea1.jpg");}else {request.setAttribute("link", "img/banner1.jpg");}request.getRequestDispatcher("productlist.jsp").forward(request, response);}else {//有fidString fid = request.getParameter("fid");CategoryService service2 = new CategoryServiceImpl();Category f = service2.findCategoryByCid(Integer.valueOf(fid));request.setAttribute("fatherC",f);List<Category> flist =  service2.findCategoryListByName("father");request.setAttribute("flist", flist);List<Category> clist =  service2.findCategoryListByName("child");request.setAttribute("clist", clist);//没实现分类添加图片if (f.getCategory_id() == 1) {request.setAttribute("link", "images/temp/banner1.jpg");}else if (f.getCategory_id() == 2){request.setAttribute("link", "images/temp/bzbig.jpg");}else if (f.getCategory_id() == 3){request.setAttribute("link", "images/temp/banner2.jpg");}else if (f.getCategory_id() == 4){request.setAttribute("link", "images/temp/perfume_Banner.jpg");}else if (f.getCategory_id() == 5){request.setAttribute("link", "img/idea1.jpg");}else {request.setAttribute("link", "img/banner1.jpg");}ProductService service = new ProductServiceImpl();List<Product> list = service.findProductByCategoryFid(Integer.valueOf(fid));request.setAttribute("productList",list);request.getRequestDispatcher("productlist.jsp").forward(request, response);}}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request,response);}
}

订单信息业务:

@WebServlet("/toOrderServlet")
public class ToOrderServlet extends HttpServlet {protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//判断是否登录HttpSession session = request.getSession();User user = (User) session.getAttribute("name");if (user != null) {//判断是否有参数uidString uid = request.getParameter("uid");if (uid == null) {//我的订单中心进入,无需添加商品CategoryService service1 = new CategoryServiceImpl();List<Category> flist = service1.findCategoryListByName("father");List<Category> clist = service1.findCategoryListByName("child");request.setAttribute("flist",flist);request.setAttribute("clist",clist);AddressService service = new AddressServiceImpl();List<Address> addresses = service.findAddressByUserId(user.getUser_id());request.setAttribute("address",addresses);//计算商品价格String pid = request.getParameter("pid");String oid = request.getParameter("oid");String count = request.getParameter("count");ProductService service2 = new ProductServiceImpl();Product p = service2.findProductById(Integer.valueOf(pid));int price = p.getProduct_price();int totalPrice = price*Integer.valueOf(count);request.setAttribute("price",price);request.setAttribute("count",count);request.setAttribute("product",p);request.setAttribute("totalPrice",totalPrice);//查询购物车数量String cartCount = "0";CartService service3 = new CartServiceImpl();if (user != null) {cartCount = String.valueOf(service3.findCartCountByUserId(user.getUser_id()));}else {cartCount = "?";}request.setAttribute("cartCount",cartCount);OrderService service4 = new OrderServiceImpl();Order o = service4.findOrderById(oid);request.setAttribute("order",o);}else {CategoryService service1 = new CategoryServiceImpl();List<Category> flist = service1.findCategoryListByName("father");List<Category> clist = service1.findCategoryListByName("child");request.setAttribute("flist",flist);request.setAttribute("clist",clist);AddressService service = new AddressServiceImpl();List<Address> addresses = service.findAddressByUserId(user.getUser_id());request.setAttribute("address",addresses);//计算商品价格String pid = request.getParameter("pid");String count = request.getParameter("count");ProductService service2 = new ProductServiceImpl();Product p = service2.findProductById(Integer.valueOf(pid));int price = p.getProduct_price();int totalPrice = price*Integer.valueOf(count);request.setAttribute("price",price);request.setAttribute("count",count);request.setAttribute("product",p);request.setAttribute("totalPrice",totalPrice);//查询购物车数量String cartCount = "0";CartService service3 = new CartServiceImpl();if (user != null) {cartCount = String.valueOf(service3.findCartCountByUserId(user.getUser_id()));}else {cartCount = "?";}request.setAttribute("cartCount",cartCount);//添加此订单为待支付订单//添加此订单的订单列表//查询该订单中商品及数量int product_quantity = Integer.valueOf(count);int product_id = p.getProduct_id();Order order = new Order(System.currentTimeMillis() +""+ user.getUser_id(),user.getUser_id(),totalPrice,new Date(),"0","0","0",product_id,product_quantity);ProductService service5 = new ProductServiceImpl();Product product = service5.findProductById(product_id);order.setProduct_name(product.getProduct_name());order.setProduct_photo(product.getProduct_photo());order.setProduct_price(product.getProduct_price());request.setAttribute("order",order);OrderService service4 = new OrderServiceImpl();service4.addOrder(order);}//            String product_quantity = count;
//            String order_id = order.getOrder_id();
//            int product_id = p.getProduct_id();
//
//            OrderList orderList = new OrderList(order_id,product_id,product_quantity);
//
//            OrderListService service5 = new OrderListServiceImpl();
//            service5.addOrderList(orderList);request.getRequestDispatcher("order.jsp").forward(request, response);}else {response.sendRedirect("login.jsp");}}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doPost(request,response);}
}

源码获取:博客首页 "资源" 里下载!

相关文章:

leetcode:Search in Rotated Sorted Array

题目要求&#xff1a; Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array return its index, otherwise return -1. You may a…

解决Debian-7.1下Chrome浏览器字体难看的问题

首先在 Advance Setting 的 font 标签页下做如下配置&#xff1a; 然后在用户目录下创建 .fonts.conf 文件&#xff0c;内容如下&#xff1a; <?xml version1.0?> <!DOCTYPE fontconfig SYSTEM fonts.dtd> <fontconfig><match target"font"&g…

HDU.4903.The only survival(组合 计数)

题目链接 惊了 \(Description\) 给定\(n,k,L\)&#xff0c;表示&#xff0c;有一张\(n\)个点的无向完全图&#xff0c;每条边的边权在\([1,L]\)之间。求有多少张无向完全图满足&#xff0c;\(1\)到\(n\)的最短路为\(k\)。\(n,k\leq 12,\ L\leq10^9\)。 \(Solution\) 考虑暴力&a…

Rocksdb 写入数据后 GetApproximateSizes 获取的大小竟然为0?

项目开发中需要从引擎 获取一定范围的数据大小&#xff0c;用作打点上报&#xff0c;测试过程中竟然发现写入了一部分数据之后通过GetApproximateSizes 获取写入的key的范围时取出来的数据大小竟然为0。。。难道发现了一个bug?&#xff08;欣喜&#xff09; 因为写入的数据是…

Java项目:在线婚纱摄影预定系统(java+javaweb+SSM+springboot+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 前后用户的登录注册&#xff0c;婚纱照片分类&#xff0c;查看&#xff0c;摄影师预 订&#xff0c;后台订单管理&#xff0c;图片管理等等。 二、项目运行 环境配置&am…

Linux Terminal 控制终端的使用

1. Open new Terminal&#xff1a;Ctrl Alt T 或者 Ctrl Shift N 2. Open Tab&#xff1a;Ctrl Shift T 3. Close Tab&#xff1a;Ctrl Shift W 4. Close Window&#xff1a;Ctrl Shift Q 5. Copy : Ctrl Shift C 6. Paste: Ctrl Shift V 7. Full Screen: F11 8.…

如何防止代码腐烂

http://blog.jobbole.com/5643/ 很多团队都有这个问题&#xff0c;一个项目的代码本来开始设计得好好的&#xff0c;一段时间以后&#xff0c;代码就会变得难以理解&#xff0c;难以维护&#xff0c;难以修改。为什么&#xff1f;我一直在思考这个问题。 让我们先看一个人的情况…

CORS在Spring中的实现

CORS: 通常情况下浏览器禁止AJAX从外部获取资源&#xff0c;因此就衍生了CORS这一标准体系&#xff0c;来实现跨域请求。 CORS是一个W3C标准&#xff0c;全称是"跨域资源共享"&#xff08;Cross-origin resource sharing&#xff09;。它允许浏览器向跨源(协议 域名…

从BloomFilter到Counter BloomFilter

文章目录前言1. Traditional BloomFilter2. Counter BloomFilter本文traditional bloomfilter 和 counter bloomfilter的C实现 均已上传至&#xff1a; https://github.com/BaronStack/BloomFilter 前言 Bloomfilter 是一个老生常谈的数据结构&#xff0c;应用在存储领域的各…

进程、线程、多线程相关总结

进程、线程、多线程相关总结 一、说说概念 1、进程&#xff08;process&#xff09; 狭义定义&#xff1a;进程就是一段程序的执行过程。 广义定义&#xff1a;进程是一个程序关于某个数据集合的一次运行。它是操作系统动态执行的基本单元&#xff0c;在传统的操作系统中&#…

Java项目:在线蛋糕商城系统(java+jsp+jdbc+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 主页显示热销商品&#xff1b;所有蛋糕商品展示&#xff0c;可进行商品搜 索&#xff1b;点击商品进入商品详情页&#xff0c;具有立即购买和加入购物 车功能&#xff0c;可…

业界对生成图片缩略图的做法归纳

网站如果有很多用户上传图片(相册&#xff0c;商品图片)&#xff0c;一般的做法是将用户图片保存在磁盘上面(数据库中记录图片的地址)。用户上传的时候按照原图、中图、小图等各个尺寸都生成一份保存在磁盘上。比如php的网店系统echsop就是这么做的&#xff0c;而shopex之类也大…

thinkPHP5.0 URL路由优化

在tp中访问页面的时候URL地址是 域名/模块/控制器/方法&#xff0c;在点击首页的时候URL是 域名/index/index/index 而不是只显示域名&#xff0c;这样不利于SEO&#xff0c;而且强迫症的我看着很不爽&#xff0c;这个时候我们需要优化路由 Route::rule(路由表达式,路由地址,请…

Rocksdb 获取当前db内部的有效key个数 (估值)

文章目录1. 基本接口2. Memtable key个数统计3. Immutable Memtable key个数统计4. Sstables key个数统计5. 疑问Rocksdb因为是AppendOnly 方式写入&#xff0c;所以没有办法提供db内部唯一key个数的接口&#xff08;可能存在多版本的key&#xff0c;对用户来说只有一个userkey…

Java项目:网上花店商城系统(java+jsp+servlert+mysql+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 一套完整的网上花店商场系统&#xff0c;系统支持前台会员的注册 登陆系统留言&#xff0c;花朵的品种选择&#xff0c;详情浏览&#xff0c;加入购物 车&#xff0c;购买花…

使用Uboot启动内核并挂载NFS根文件系统

配置编译好内核之后&#xff0c;将生成的内核文件uImage拷贝到/tftpboot/下&#xff0c;通过tftp服务器将内核下载到开发板&#xff0c;使用命令&#xff1a;tftp 31000000 uImage.下载完成之后配置bootargs环境变量&#xff1a;setenv bootargs noinitrd consolettySAC0,11520…

Centos系统上安装php遇到的错误解决方法集锦

Centos系统上安装php遇到的错误解决方法集锦1.configure: error: xml2-config not found. Please check your libxml2 installationyum install libxml2 libxml2-devel2.configure: error: Cannot find OpenSSL’s yum install openssl openssl-devel3.configure: error: Pleas…

2.27 MapReduce Shuffle过程如何在Job中进行设置

一、shuffle过程 总的来说&#xff1a; *分区 partitioner*排序 sort*copy (用户无法干涉) 拷贝*分组 group可设置 *压缩 compress*combiner map task端的Reduce二、示例 package com.ibeifeng.hadoop.senior.mapreduce;import java.io.IOException; import java.util.StringTo…

Rocksdb Slice使用中的一个小坑

本文记录一下使用Rocksdb Slice过程中的一个小小坑&#xff0c;差点没一口老血吐出来。 rocksdb的Slice 数据结构是一个小型得不可变类string数据结构&#xff0c;设计出来的目的是为了保证rocksdb内部处理用户输入的key在从内存到持久化磁盘的整个处理链路是不会被修改的&…

Java项目:仿天猫网上商城项目(java+jsp+servlet+mysql+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 前台&#xff1a; * 用户模块 * 分类模块 * 商品模块 * 购物车模块 * 订单模块 后台&#xff1a; * 管理员模块 * 分类管理模块 * 商品管理模块 * 订单模块…

转--Android如何在java代码中设置margin

3 在Java代码里设置button的margin(外边距)&#xff1f; 1、获取按钮的LayoutParams LinearLayout.LayoutParams layoutParams (LinearLayout.LayoutParams)button.getLayoutParams(); 2、在LayoutParams中设置margin layoutParams.setMargins(100,20,10,5);//4个参数按顺序分…

poj12月其他题解(未完)

最近编程的时间比较少啊…… poj3253 就是个合并果子&#xff0c;各种优先队列即可&#xff08;显然单调队列最优&#xff09; poj3263 线段树统计每个点被覆盖了多少次即可&#xff0c;注意要去重 poj3625 最小生成树 poj3626 bfs poj3624 01背包 poj3615 floyd即可 poj3278 简…

0409-0416的笔记

1 获取前几天&#xff0c;近几个月的时间 function getDay(day) {var today new Date();var targetday_milliseconds today.getTime() 1000 * 60 * 60 * 24 * day;today.setTime(targetday_milliseconds); //注意&#xff0c;这行是关键代码var tYear today.getFullYear();…

Linux NUMA 架构 :基础软件工程师需要知道一些知识

文章目录前言从物理CPU、core到HT(hyper-threading)UMA&#xff08;Uniform memory access&#xff09;NUMA架构NUMA下的内存分配策略1. MPOL_DEFAULT2. MPOL_BIND3. MPOL_INTERLEAVE4. MPOL_PREFERRED5. 一些NUMA架构下的内核配置总结参考前言 NUMA&#xff08;Non-Uniform m…

Java项目:网上书城+后台管理系统(java+jsp+servlert+mysql+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述(附带IW文档) 功能&#xff1a; 前台&#xff1a; * 用户模块 * 分类模块 * 图书模块 * 购物车模块 * 订单模块 后台&#xff1a; * 管理员模块 * 分类管理模块 * 图书管理模块 * 订单模块 …

java.util.concurrent包API学习笔记

newFixedThreadPool 创建一个固定大小的线程池。 shutdown()&#xff1a;用于关闭启动线程&#xff0c;如果不调用该语句&#xff0c;jvm不会关闭。 awaitTermination()&#xff1a;用于等待子线程结束&#xff0c;再继续执行下面的代码。该例中我设置一直等着子线程结束。Java…

oracle读书记录

很久没有关注自己怕博客了&#xff0c;差不多有两年了。虽然这两年来一直关注51CTO,每天上班打开电脑或者周末在家开启电脑的时候都会浏览一下&#xff0c;这已经是习惯了&#xff0c;但是把自己的blog给忘了。今天&#xff0c;周末&#xff0c;2013年12月21日&#xff0c;同往…

输入、方法的运用

/ /猜数游戏,编写一个功能,完成猜数游戏,产生一个1~10之间的随机数 //与输入的数对对比,返回结果 猜中和没猜中 import java.util.Scanner; //引入&#xff08;输入&#xff09;的util包Scanner public class HelloWorld { public static void main(String[] args) {System…

Rocksdb 利用recycle_log_file_num 重用wal-log文件

recycle_log_file_num 复用wal文件信息&#xff0c; 优化wal文件的空间分配&#xff0c;减少pagecache中文件元信息的更新开销。 为同事提供了一组rocksdb写优化参数之后有一个疑惑的现象被问到&#xff0c;发现之前的一些代码细节有遗忘情况&#xff0c;同时也发现了这个参数…

Java项目:网上商城系统(java+jsp+servlert+mysql+ajax)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述&#xff08;需求文档PPT&#xff09; 功能&#xff1a; 主页显示热销商品&#xff1b;所有商品展示&#xff0c;可进行商品搜索&#xff1b;点 击商品进入商品详情页&#xff0c;显示库存&…