基于javaweb+mysql的jsp+servlet空调商城系统(java+servlet+jsp+jdbc+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet空调商城系统(java+servlet+jsp+jdbc+mysql)
项目介绍
本项目分为前后台,前台为用户角色登录,后台为管理员角色登录; 管理员角色包含以下功能: 管理员登录,会员信息管理,商城综合统计,资讯管理,友情链接管理,轮播图管理,关于我们管理,空调类别管理,空调平台管理,空调商品管理,空调库存管理,订单管理,留言管理等功能。
用户角色包含以下功能: 用户首页,用户登录注册,查看商品详情评价商品,查看购物车,提交订单,查看订单详情,按照类别查看空调,查看资讯,在站点上留言,关于我们信息,修改查看会员信息,查看我收藏的空调信息,个人收货地址管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7、8.0等版本均可; 6.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
技术栈
Servlet、JSP、JDBC、MySQL5.7、Tomcat8
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目; 3. 将项目中util/SimpleDataSource.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080/jsp_kongtiaoshop 登录 用户账号/密码:user/123456 管理员账号/密码:admin/admin
Orderitem orderitem = new Orderitem();
orderitem.setProduct(cartItem.getProduct());
orderitem.setCount(cartItem.getCount());
orderitem.setPid(cartItem.getProduct().getPid());
orderitem.setSubtotal(cartItem.getSubtotle());
orderitem.setOid(orders.getOid());
orders.getOiList().add(orderitem);
orderService.toOrderItem(orderitem);
cart.clearCart();
request.getSession().setAttribute("orders", orders);
orders.setReceiveinfo(receiveInfo);
orders.setPhonum(phoNum);
orders.setAccepter(accepter);
orderService.payOrder(orders);
return "redirect:myOrder.action?page=1";
//payOrderAganin
@RequestMapping("/payOrderAganin")
public String payOrderAganin(@RequestParam int oid,HttpServletRequest request){
Orders noPayOrder = orderService.findOrderByOid(oid);
request.getSession().setAttribute("orders", noPayOrder);
Cart cart=getCart(request);
cart.clearCart();
return "redirect:myCart.action";
// 删除某个购物项
@RequestMapping("/delProFromCart")
public String delProFromCart(@RequestParam int pid,HttpServletRequest request){
Cart cart=getCart(request);
cart.delProFromCart(pid);
return "redirect:myCart.action";
public Cart getCart(HttpServletRequest request) {
Cart cart = (Cart) request.getSession().getAttribute("cart");
if (cart == null) {
@RequestMapping("/myCart")
public String myCart(HttpServletRequest request,Model model){
User loginUser = (User) request.getSession().getAttribute("loginUser");
if (loginUser == null) {
model.addAttribute("message","您还没有登录!");
return "msg";
return "cart";
// 清空购物车
@RequestMapping("/clearCart")
public String clearCart(HttpServletRequest request){
Cart cart=getCart(request);
@RequestMapping("/admin")
public String AdminIndex(){
return "admin/index";
//admin/adminUser_login.action
//adminUser_login管理员登录
@RequestMapping("/admin/adminUser_login")
public String adminUser_login(HttpServletRequest request,Model model,@RequestParam String username,@RequestParam String password) throws Exception{
Adminuser adminuserLogin = userService.adminUser_login(username,password);
System.out.println(username);
System.out.println(password);
if(adminuserLogin == null){
model.addAttribute("message", "改用户未被授予管理员身份!");
orders.setPhonum(phoNum);
orders.setAccepter(accepter);
orderService.payOrder(orders);
return "redirect:myOrder.action?page=1";
//payOrderAganin
@RequestMapping("/payOrderAganin")
public String payOrderAganin(@RequestParam int oid,HttpServletRequest request){
Orders noPayOrder = orderService.findOrderByOid(oid);
request.getSession().setAttribute("orders", noPayOrder);
return "order";
// 查询myOrder
if (loginUser == null) {
model.addAttribute("message","您还没有登录!");
return "msg";
return "cart";
// 清空购物车
@RequestMapping("/clearCart")
public String clearCart(HttpServletRequest request){
Cart cart=getCart(request);
cart.clearCart();
return "redirect:myCart.action";
public String userLogout(HttpServletRequest request,
HttpServletResponse response, Model model) {
request.getSession().removeAttribute("loginUser");
response.setHeader("content-type", "text/html;charset=UTF-8");
response.setHeader("refresh", "5;url=/shop/index.action");
model.addAttribute("message", "退出成功,系统将在5秒之后跳转到首页......");
return "msg";
//进入管理员页面
@RequestMapping("/admin")
public String AdminIndex(){
return "admin/index";
//admin/adminUser_login.action
//adminUser_login管理员登录
@RequestMapping("/admin/adminUser_login")
public String adminUser_login(HttpServletRequest request,Model model,@RequestParam String username,@RequestParam String password) throws Exception{
Adminuser adminuserLogin = userService.adminUser_login(username,password);
System.out.println(username);
System.out.println(password);
if(adminuserLogin == null){
model.addAttribute("message", "改用户未被授予管理员身份!");
return "admin/index";
request.getSession().setAttribute("orders", noPayOrder);
return "order";
// 查询myOrder
@RequestMapping("/myOrder")
public String myOrder(@RequestParam int page, Model model,
HttpServletRequest request) throws Exception {
User loginUser = (User) request.getSession().getAttribute("loginUser");
PageBean<Orders> pageBean = orderService.findOrderByUidAndPage(page,loginUser.getUid());
model.addAttribute("pageBean", pageBean);
return "orderList";
// 确认收货
@RequestMapping("/updateState")
cart = new Cart();
request.getSession().setAttribute("cart", cart);
return cart;
登录管理控制层:
@Controller
public class loginController {
@Autowired
private UserService userService;
@RequestMapping("login")
public String login() {
return "login";
// 用户登录
// 用户退出
@RequestMapping("userLogout")
public String userLogout(HttpServletRequest request,
HttpServletResponse response, Model model) {
request.getSession().removeAttribute("loginUser");
response.setHeader("content-type", "text/html;charset=UTF-8");
response.setHeader("refresh", "5;url=/shop/index.action");
model.addAttribute("message", "退出成功,系统将在5秒之后跳转到首页......");
return "msg";
//进入管理员页面
@RequestMapping("/admin")
public String AdminIndex(){
return "admin/index";
@RequestMapping("/myCart")
public String myCart(HttpServletRequest request,Model model){
User loginUser = (User) request.getSession().getAttribute("loginUser");
if (loginUser == null) {
model.addAttribute("message","您还没有登录!");
return "msg";
return "cart";
// 清空购物车
@RequestMapping("/clearCart")
public String clearCart(HttpServletRequest request){
Cart cart=getCart(request);
Orders orders = new Orders();
Cart cart = (Cart) request.getSession().getAttribute("cart");
User loginUser = (User) request.getSession().getAttribute("loginUser");
if(loginUser==null){
model.addAttribute("message", "对不起您还没有登录");
return "msg";
// 0表示没有付款、1表示已付款即将发货 2表示确认收货 3表示交易成功
orders.setState(0);
orders.setOrderTime(new Date());
orders.setUid(loginUser.getUid());
orders.setMoney(cart.getTotale());
orderService.toOrder(orders);
Map<Integer, CartItem> cartItems = cart.getCartItem();
Orders orders = new Orders();
Cart cart = (Cart) request.getSession().getAttribute("cart");
User loginUser = (User) request.getSession().getAttribute("loginUser");
if(loginUser==null){
model.addAttribute("message", "对不起您还没有登录");
return "msg";
// 0表示没有付款、1表示已付款即将发货 2表示确认收货 3表示交易成功
orders.setState(0);
orders.setOrderTime(new Date());
orders.setUid(loginUser.getUid());
orders.setMoney(cart.getTotale());
orderService.toOrder(orders);
Map<Integer, CartItem> cartItems = cart.getCartItem();
@RequestMapping("/clearCart")
public String clearCart(HttpServletRequest request){
Cart cart=getCart(request);
cart.clearCart();
return "redirect:myCart.action";
// 删除某个购物项
@RequestMapping("/delProFromCart")
public String delProFromCart(@RequestParam int pid,HttpServletRequest request){
Cart cart=getCart(request);
cart.delProFromCart(pid);
return "msg";
return "cart";
// 清空购物车
@RequestMapping("/clearCart")
public String clearCart(HttpServletRequest request){
Cart cart=getCart(request);
cart.clearCart();
return "redirect:myCart.action";
// 删除某个购物项
@RequestMapping("/delProFromCart")
public String delProFromCart(@RequestParam int pid,HttpServletRequest request){
Cart cart=getCart(request);
cart.delProFromCart(pid);
Adminuser adminuserLogin = userService.adminUser_login(username,password);
System.out.println(username);
System.out.println(password);
if(adminuserLogin == null){
model.addAttribute("message", "改用户未被授予管理员身份!");
return "admin/index";
request.getSession().setAttribute("adminuserLogin", adminuserLogin);
// model.addAttribute("adminuserLogin", adminuserLogin);
return "admin/home";
订单管理控制层: