当前位置:   article > 正文

基于ssh的网上商城系统_采用ssh架构开发一个网上商城。

采用ssh架构开发一个网上商城。

目录

系统运行环境

系统介绍

系统功能

系统产出

系统运行环境:

1、mysql5.6+

2、jdk1.8

3、tomcat8或者tomcat9

4、idea、eclipse或者MyEclipse

系统介绍:

       系统框架采用ssh结合mvc开发思想进行的系统开发。包含网上商城网站和后台管理平台两个端。其中网站用于普通用户注册、登录进行商品加入购物车及下单等操作;后台管理平台用于管理员用户登录系统对商品、订单、用户及系统进行管理。

系统功能:

1、网站首页

 

  1. <%@ page language="java" import="java.util.*" contentType="text/html;charset=UTF-8"%>
  2. <%@ taglib prefix="s" uri="/struts-tags" %>
  3. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml">
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  8. <title></title>
  9. <link rel="stylesheet" type="text/css" href="js/style.css" />
  10. <style>
  11. .main_iframe {
  12. Z-INDEX: 1; VISIBILITY: inherit; WIDTH: 100%; HEIGHT: 92%
  13. </style>
  14. </head>
  15. <body>
  16. <s:if test="#request.listCommodityClasses">
  17. <div id="main_container">
  18. <div class="top_bar"></div>
  19. <div id="header">
  20. <div id="divstr"><br/><h2>欢迎来到网上商城</h2><h3>
  21. <script language=JavaScript >
  22. var today = new Date();
  23. var strDate = ( today.getYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日");
  24. /*var hh = today.getHours();
  25. if(hh<10) hh = '0' + hh;
  26. var mm = today.getMinutes();
  27. if(mm<10) mm = '0' + mm;
  28. var ss = today.getSeconds();
  29. if(ss<10) ss = '0' + ss;
  30. */
  31. var n_day = today.getDay();
  32. var ww;
  33. switch (n_day)
  34. {
  35. case 0:{ww = "星期日";} break;
  36. case 1:{ww = "星期一";} break;
  37. case 2:{ww = "星期二";} break;
  38. case 3:{ww = "星期三";} break;
  39. case 4:{ww = "星期四";} break;
  40. case 5:{ww = "星期五";} break;
  41. case 6:{ww = "星期六";} break;
  42. case 7:{ww = "星期日";} break;
  43. }
  44. strDate="今天是:" + ww+"</font>";
  45. document.write(strDate);
  46. </script></h3></div>
  47. <!-- end of oferte_content-->
  48. </div>
  49. <div id="main_content">
  50. <div id="menu_tab">
  51. <div class="left_menu_corner"></div>
  52. <ul class="menu">
  53. <li><a href="GoIndexAction.action" class="nav1">首页</a></li>
  54. <li class="divider"></li>
  55. <li><a href="GoIndexAction.action" class="nav2">在线购物</a></li>
  56. <li class="divider"></li>
  57. <li><a href="showCar.jsp" class="nav5">我的购物车</a></li>
  58. <li class="divider"></li>
  59. <c:if test="${empty sessionScope.user.username}">
  60. <li class="divider"></li>
  61. <li><a href="login.jsp" class="nav3" >用户登录</a></li>
  62. <li class="divider"></li>
  63. <li><a href="register.jsp" class="nav6">用户注册 </a></li>
  64. </c:if>
  65. <li class="divider"></li>
  66. </ul>
  67. <div class="right_menu_corner"></div>
  68. </div><!-- end of menu tab -->
  69. </div>
  70. <div class="crumb_navigation">
  71. 导航: <span class="current"><a href="GoIndexAction.action">首页</a></span>
  72. </div > <div align="right"><form name="searchform" action="CommodityAction!findCommodityByName.action" method="post">
  73. <input id="commodity.commodityName" name="commodity.commodityName" style="font-size: 10pt; color: rgb(85, 85, 85);" onfocus="if(this.value=='请输入您所要查找的商品名称'){this.value='';}" onblur="if(this.value==''){this.value='请输入您所要查找的商品名称';}" value="请输入您所要查找的商品名称" size="25" maxlength="30" type="text" />
  74. <input name="搜索" type="submit" value="搜索" />
  75. </form></div>
  76. <table border="0" cellpadding="0" cellspacing="0" align="center" width=100% height=400px>
  77. <tr>
  78. <td class="left_content">
  79. <table>
  80. <tr>
  81. <td class="title_box">商品分类</td></tr>
  82. <tr><td>
  83. <ul class="left_menu">
  84. <s:iterator value="#request.listCommodityClasses" status="stu" id="classes">
  85. <s:if test="#stu.odd==true">
  86. <li class="odd">
  87. <s:a href="CommodityAction!findCommodityByClass.action?commodityClassId=%{#classes.commodityClassId} ">
  88. <s:property value="#classes.commodityClassName"/>
  89. </s:a>
  90. </li>
  91. </s:if>
  92. <s:else>
  93. <li class="even">
  94. <s:a href="CommodityAction!findCommodityByClass.action?commodityClassId=%{#classes.commodityClassId} ">
  95. <s:property value="#classes.commodityClassName"/>
  96. </s:a>
  97. </li>
  98. </s:else>
  99. </s:iterator>
  100. </ul><br/></td>
  101. </tr>
  102. <!--<tr>
  103. <td align=center class="title_box">论坛公告
  104. </td></tr>
  105. <tr>
  106. <td align=center ><marquee height=120 direction="up" scrollamount=3 onmouseover="this.stop()" onmouseout="this.start()">
  107. <h3>网上商城系统开通了,欢迎广大客户光临</h3></marquee>
  108. </td></tr>
  109. --></table>
  110. </td>
  111. <td class="center_content" width=100% height=400px>
  112. <iframe class=main_iframe id=frmright name="frmright" frameborder=0 scrolling=auto src="product.jsp">
  113. </iframe>
  114. </td>
  115. <td class="right_content"><table>
  116. <tr>
  117. <td class="shopping_cart"><table>
  118. <tr><td class="cart_title">购物车 </td>
  119. </tr>
  120. <tr><td class="cart_icon">
  121. <a href="showCar.jsp" title="">
  122. <img src="images/shoppingcart.png" alt="" title="" width="48" height="48" border="0" /></a>
  123. </td>
  124. </tr></table>
  125. </td></tr>
  126. <tr><td> <c:if test="${empty sessionScope.user.username}">
  127. <form action="UserAction!login.action" name="form" method="post" >
  128. <div class="title_box">用户登录</div>
  129. <div class="border_box">
  130. <p>用户名:<input id="username" name="user.username" type="text" style="width:110px"/></p>
  131. <p>密&nbsp;&nbsp;&nbsp;&nbsp;码:<input id="password" name="user.password" type="password" style="width:110px"/></p>
  132. <p>&nbsp;&nbsp;&nbsp;&nbsp;<input name="提交" type="submit" value="登录" /><input name="重置" type="reset" value="重置" />
  133. </p>
  134. <p align="center">&nbsp;&nbsp;&nbsp;[<a href="register.jsp">新用户注册</a>] &nbsp;[<a href="findPass.jsp" >忘记密码</a>]</p>
  135. </div> </form> </c:if>
  136. <c:if test="${!empty sessionScope.user.username}">
  137. <div class="title_box">用户信息</div>
  138. <div class="border_box">
  139. <br/>
  140. <p>欢迎登陆:${sessionScope.user.username}</p><br/>
  141. <p> [<a href="OrderFormAction!findOrderFormByUserName.action?orderForm.username=${sessionScope.user.username}">我的订单</a>]&nbsp;&nbsp; [<a href="updatePass.jsp" >修改密码</a>] </p>
  142. <p> [<a href="userInfo.jsp">个人信息</a>]&nbsp;&nbsp; [<a href="UserAction!logout.action" onclick="return confirm('确定要退出吗?')" >退出系统</a>] </p>
  143. </div>
  144. </c:if>
  145. </td>
  146. </tr>
  147. </table></td>
  148. </tr>
  149. </table>
  150. <div class="footer" align="center"><br/>&copy;&nbsp;&nbsp;|&nbsp;XXXX&nbsp;|&nbsp;版权所有&nbsp;|&nbsp;网上商城系统<br/><a href="admin/login.jsp">后台管理</a></div>
  151. </div>
  152. </s:if>
  153. <s:else><s:action name="GoIndexAction" executeResult="true"></s:action>
  154. </s:else>
  155. </body>
  156. </html>
  1. package cn.itbaizhan.action;
  2. import java.util.Collection;
  3. import java.util.Map;
  4. import javax.annotation.Resource;
  5. import org.springframework.context.annotation.Scope;
  6. import org.springframework.stereotype.Component;
  7. import cn.itbaizhan.po.User;
  8. import cn.itbaizhan.service.UserService;
  9. import com.opensymphony.xwork2.ActionContext;
  10. import com.opensymphony.xwork2.ActionSupport;
  11. //import com.cds.po.Department;
  12. //import com.cds.po.Role;
  13. //import com.cds.service.DepartmentService;
  14. //import com.cds.service.RoleService;
  15. @SuppressWarnings("serial")
  16. @Component("userAction")
  17. @Scope("prototype")//多例,每个请求生成一个新的action
  18. public class UserAction extends ActionSupport {
  19. private User user;
  20. //要调用UserService的方法,所以要声明,让spring把其实现类注入。@Resource 默认按 byName 自动注入
  21. @Resource(name="userServiceImpl")
  22. UserService service;
  23. public UserService getService() {
  24. return service;
  25. }
  26. public void setService(UserService service) {
  27. this.service = service;
  28. }
  29. public User getUser() {
  30. return user;
  31. }
  32. public void setUser(User user) {
  33. this.user = user;
  34. }
  35. @Override
  36. public String execute() throws Exception {
  37. // 不要直接访问数据库,应该访问业务逻辑层service,而service去访问DAO,dao去访问数据库
  38. String username= user.getUsername();
  39. System.out.println(username);
  40. User user = service.findUserByName(username);
  41. if(user==null){
  42. this.service.save(this.user);
  43. return "success";
  44. }
  45. else{
  46. return "error";
  47. }
  48. }
  49. //列表
  50. @SuppressWarnings("unchecked")
  51. public String listUser(){
  52. Map request = (Map) ActionContext.getContext().get("request");
  53. request.put("listUsers", service.findAllUsers());
  54. System.out.println("listUsers"+service.findAllUsers().size());
  55. return "listUser";
  56. }
  57. //查询
  58. @SuppressWarnings("unchecked")
  59. public String queryUser(){
  60. String username= user.getUsername();
  61. System.out.println(username);
  62. String name= user.getName();
  63. User user=this.service.queryUser(username);
  64. System.out.println("user:"+user);
  65. Map request = (Map) ActionContext.getContext().get("request");
  66. request.put("queryUser", user);
  67. //System.out.println("queryUser"+service.queryUser().size());
  68. return "queryUser";
  69. }
  70. public String deleteUser(){
  71. this.service.delete(user);
  72. return "deleteUser";
  73. }
  74. public String findUserById(){
  75. user = this.service.findUserById(user.getUserId());
  76. return "findUser";
  77. }
  78. public String updateUser(){
  79. this.service.update(user);
  80. System.out.println("user:"+user.getUserId());
  81. ActionContext.getContext().put("updatemessage", "您的信息已经更新!");
  82. return "updateUser";
  83. }
  84. @SuppressWarnings("unchecked")
  85. public String addUser(){
  86. Map request = (Map) ActionContext.getContext().get("request");
  87. return "adduser";
  88. }
  89. //个人密码跳转
  90. /*public String updatePassword(){
  91. return "updatePassword";
  92. }
  93. */
  94. public String findUser()
  95. {
  96. String username= user.getUsername();
  97. System.out.println("username:"+username);
  98. String name= user.getName();
  99. System.out.println("name:"+name);
  100. String sex= user.getSex();
  101. System.out.println("sex:"+sex);
  102. String post= user.getPost();
  103. System.out.println("post:"+post);
  104. String address= user.getAddress();
  105. System.out.println("address:"+address);
  106. String phone= user.getPhone();
  107. System.out.println("phone:"+phone);
  108. String email= user.getEmail();
  109. System.out.println("email:"+email);
  110. User user=this.service.findUserByinfo(username, name,sex,phone, post, address, email);
  111. System.out.println("user:"+user);
  112. if(user==null){
  113. ActionContext.getContext().put("findUsernull", "没有该用户信息!");
  114. return "findUsernull";
  115. }else{
  116. ActionContext.getContext().getSession().put("findUser", user);
  117. return "findUser";
  118. }
  119. }
  120. //修改密码
  121. public String upPass()
  122. {
  123. this.service.update(user);
  124. System.out.println("user:"+user.getUserId());
  125. ActionContext.getContext().put("upPass", "您的密码已经修改!");
  126. return "upPass";
  127. }
  128. //重设密码
  129. public String updatePass()
  130. {
  131. this.service.update(user);
  132. System.out.println("user:"+user.getUserId());
  133. ActionContext.getContext().put("updatePass", "您的密码已经更改!");
  134. return "updatePass";
  135. }
  136. //用户注册验证
  137. public String register()
  138. {
  139. String username= user.getUsername();
  140. System.out.println(username);
  141. User user = service.findUserByName(username);
  142. System.out.println("name:"+username+",user:"+user);
  143. if(user == null){
  144. ActionContext.getContext().put("regmessage", username+"可以注册");
  145. return "regsuccess";
  146. }else{
  147. ActionContext.getContext().put("regmessage", username+"已经被注册");
  148. return "regerror";
  149. }
  150. }
  151. //用户登录
  152. public String login(){
  153. String username= user.getUsername();
  154. System.out.println(username);
  155. String password=user.getPassword();
  156. User user = service.getUserByLoginNameAndPassword(username,password);
  157. System.out.print("name:"+username+"pass"+password+"user"+user);
  158. if(user == null){
  159. ActionContext.getContext().put("message", "用户名或密码错误");
  160. return "login";
  161. }else{
  162. ActionContext.getContext().getSession().put("user", user);
  163. return "index";
  164. }
  165. }
  166. //用户退出
  167. public String logout(){
  168. ActionContext.getContext().getSession().clear();
  169. return "logout";
  170. }
  171. }
  1. package cn.itbaizhan.service;
  2. import java.util.List;
  3. import java.util.Map;
  4. import cn.itbaizhan.po.User;
  5. public interface UserService {
  6. // 和UserDao的方法一样,可以封装,因为这边只是调用
  7. public void save(User user);
  8. public void delete(User id);
  9. public User findUserById(int id);
  10. public List<User> findAllUsers();
  11. public void update(User user);
  12. //public void initPassword(User user);
  13. public User getUserByLoginNameAndPassword(String username, String password);
  14. public User findUserByName(String username);
  15. public User queryUser(String username);
  16. public User findUserByinfo(String username, String name, String sex,
  17. String phone, String post, String address, String email);
  18. }
  1. package cn.itbaizhan.service.impl;
  2. import java.util.List;
  3. import javax.annotation.Resource;
  4. import org.springframework.stereotype.Component;
  5. import cn.itbaizhan.dao.UserDao;
  6. import cn.itbaizhan.po.User;
  7. import cn.itbaizhan.service.UserService;
  8. //把类交给spring管理(如同配置bean节点)此类受spring事务管理
  9. @Component("userServiceImpl")
  10. public class UserServiceImpl implements UserService {
  11. //要调用dao层代码,所以要有UserDao的对象,把其实现类靠spring注入
  12. @Resource(name="userDaoImpl")
  13. private UserDao userDao;
  14. public UserDao getUserDao() {
  15. return userDao;
  16. }
  17. public void setUserDao(UserDao userDao) {
  18. this.userDao = userDao;
  19. }
  20. public void delete(User user) {
  21. this.userDao.delete(user);
  22. }
  23. public List<User> findAllUsers() {
  24. return this.userDao.findAllUsers();
  25. }
  26. public User findUserById(int id) {
  27. return this.userDao.findUserById(id);
  28. }
  29. public void save(User user) {
  30. this.userDao.save(user);
  31. }
  32. public void update(User user) {
  33. this.userDao.update(user);
  34. }
  35. public User getUserByLoginNameAndPassword(String username, String password) {
  36. return this.userDao.getUserByLoginNameAndPassword(username,password);
  37. }
  38. public User findUserByName(String username) {
  39. return this.userDao.findUserByName(username);
  40. }
  41. public User queryUser(String username) {
  42. return this.userDao.queryUser(username);
  43. }
  44. public User findUserByinfo(String username, String name, String sex,
  45. String phone, String post, String address, String email) {
  46. return this.userDao.findUserByinfo(username, name,sex,phone, post, address, email);
  47. }
  48. }
  1. package cn.itbaizhan.dao;
  2. import java.util.List;
  3. import cn.itbaizhan.po.User;
  4. public interface UserDao {
  5. public void save(User user);
  6. public void delete(User user);
  7. public User findUserById(int id);
  8. public User findUserByinfo(String username, String name, String sex,String phone,
  9. String post,String address, String email);
  10. public List<User> findAllUsers();
  11. public void update(User user);
  12. //public void initPassword(User user);
  13. public User getUserByLoginNameAndPassword(String username, String password);
  14. public User findUserByName(String username);
  15. public User queryUser(String username);
  16. }
  1. package cn.itbaizhan.dao.impl;
  2. import java.util.List;
  3. import javax.annotation.Resource;
  4. import org.springframework.orm.hibernate3.HibernateTemplate;
  5. import org.springframework.stereotype.Component;
  6. import cn.itbaizhan.dao.UserDao;
  7. import cn.itbaizhan.po.User;
  8. @Component("userDaoImpl")
  9. public class UserDaoImpl implements UserDao {
  10. //使用spring对Hibernate的模版 HibernateTemplate
  11. @Resource(name="hibernateTemplate")
  12. private HibernateTemplate hibernateTemplate;
  13. public void delete(User user) {
  14. hibernateTemplate.delete(user);
  15. }
  16. @SuppressWarnings("unchecked")//不检查,当编码可能存在警告时,比如安全警告,可以用它来消除
  17. public List<User> findAllUsers() {
  18. String hql = "from User";
  19. return (List<User>)hibernateTemplate.find(hql);
  20. }
  21. public User findUserById(int id) {
  22. User user = (User)hibernateTemplate.get(User.class, id);
  23. return user;
  24. }
  25. public void save(User user) {
  26. System.out.println(user);
  27. hibernateTemplate.save(user);
  28. }
  29. public void update(User user) {
  30. hibernateTemplate.update(user);
  31. }
  32. public HibernateTemplate getHibernateTmeplate() {
  33. return hibernateTemplate;
  34. }
  35. public void setHibernateTmeplate(HibernateTemplate hibernateTemplate) {
  36. this.hibernateTemplate = hibernateTemplate;
  37. }
  38. //获取用户
  39. public User getUserByLoginNameAndPassword(String username, String password) {
  40. System.out.println("用户名"+username);
  41. return (User) hibernateTemplate.getSessionFactory().openSession().createQuery(
  42. "from User u where u.username=? and u.password=?").setParameter(0, username).setParameter(1, password).uniqueResult();
  43. }
  44. public User findUserByName(String username) {
  45. System.out.println("用户名:"+username);
  46. return (User) hibernateTemplate.getSessionFactory().openSession().createQuery(
  47. "from User u where u.username=?").setParameter(0, username).uniqueResult();
  48. }
  49. public User queryUser(String username) {
  50. //String hql = "from User";
  51. return (User)hibernateTemplate.getSessionFactory().openSession().createQuery(
  52. "from User u where u.username=? ").setParameter(
  53. 0, username).uniqueResult();
  54. }
  55. public User findUserByinfo(String username, String name, String sex,
  56. String phone, String post, String address, String email) {
  57. return (User)hibernateTemplate.getSessionFactory().openSession().createQuery(
  58. "from User u where u.username=? and u.name=? and u.sex=? and u.phone=? and u.post=? and u.address=? and u.email=?").setParameter(
  59. 0, username).setParameter(1,name).setParameter(2,sex).setParameter(3,phone).setParameter(4,post).setParameter(5,address).setParameter(6,email).uniqueResult();
  60. }
  61. }

2、添加购物车

3、提交订单

 

4、订单付款

 

5、我的订单

 

6、后台管理首页

 

7、后端管理主页

 

8、商品管理

 

9、订单管理

 

10、用户管理

 

11、系统管理

 

系统产出:

1、程序源码包

2、数据库初始化脚本文件 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/244956
推荐阅读
相关标签
  

闽ICP备14008679号