赞
踩
目录
1、mysql5.6+
2、jdk1.8
3、tomcat8或者tomcat9
4、idea、eclipse或者MyEclipse
系统框架采用ssh结合mvc开发思想进行的系统开发。包含网上商城网站和后台管理平台两个端。其中网站用于普通用户注册、登录进行商品加入购物车及下单等操作;后台管理平台用于管理员用户登录系统对商品、订单、用户及系统进行管理。
1、网站首页
- <%@ page language="java" import="java.util.*" contentType="text/html;charset=UTF-8"%>
-
- <%@ taglib prefix="s" uri="/struts-tags" %>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title></title>
- <link rel="stylesheet" type="text/css" href="js/style.css" />
-
- <style>
- .main_iframe {
- Z-INDEX: 1; VISIBILITY: inherit; WIDTH: 100%; HEIGHT: 92%
- </style>
-
-
- </head>
- <body>
- <s:if test="#request.listCommodityClasses">
-
- <div id="main_container">
- <div class="top_bar"></div>
- <div id="header">
-
- <div id="divstr"><br/><h2>欢迎来到网上商城</h2><h3>
- <script language=JavaScript >
- var today = new Date();
- var strDate = ( today.getYear() + "年" + (today.getMonth() + 1) + "月" + today.getDate() + "日");
- /*var hh = today.getHours();
- if(hh<10) hh = '0' + hh;
- var mm = today.getMinutes();
- if(mm<10) mm = '0' + mm;
- var ss = today.getSeconds();
- if(ss<10) ss = '0' + ss;
- */
- var n_day = today.getDay();
- var ww;
-
- switch (n_day)
- {
- case 0:{ww = "星期日";} break;
- case 1:{ww = "星期一";} break;
- case 2:{ww = "星期二";} break;
- case 3:{ww = "星期三";} break;
- case 4:{ww = "星期四";} break;
- case 5:{ww = "星期五";} break;
- case 6:{ww = "星期六";} break;
- case 7:{ww = "星期日";} break;
- }
- strDate="今天是:" + ww+"</font>";
- document.write(strDate);
- </script></h3></div>
- <!-- end of oferte_content-->
- </div>
-
- <div id="main_content">
- <div id="menu_tab">
- <div class="left_menu_corner"></div>
- <ul class="menu">
- <li><a href="GoIndexAction.action" class="nav1">首页</a></li>
- <li class="divider"></li>
- <li><a href="GoIndexAction.action" class="nav2">在线购物</a></li>
- <li class="divider"></li>
- <li><a href="showCar.jsp" class="nav5">我的购物车</a></li>
- <li class="divider"></li>
- <c:if test="${empty sessionScope.user.username}">
- <li class="divider"></li>
- <li><a href="login.jsp" class="nav3" >用户登录</a></li>
- <li class="divider"></li>
- <li><a href="register.jsp" class="nav6">用户注册 </a></li>
- </c:if>
- <li class="divider"></li>
- </ul>
-
- <div class="right_menu_corner"></div>
- </div><!-- end of menu tab -->
-
- </div>
-
- <div class="crumb_navigation">
- 导航: <span class="current"><a href="GoIndexAction.action">首页</a></span>
-
- </div > <div align="right"><form name="searchform" action="CommodityAction!findCommodityByName.action" method="post">
- <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" />
- <input name="搜索" type="submit" value="搜索" />
- </form></div>
- <table border="0" cellpadding="0" cellspacing="0" align="center" width=100% height=400px>
- <tr>
- <td class="left_content">
- <table>
- <tr>
- <td class="title_box">商品分类</td></tr>
- <tr><td>
- <ul class="left_menu">
- <s:iterator value="#request.listCommodityClasses" status="stu" id="classes">
- <s:if test="#stu.odd==true">
- <li class="odd">
- <s:a href="CommodityAction!findCommodityByClass.action?commodityClassId=%{#classes.commodityClassId} ">
- <s:property value="#classes.commodityClassName"/>
- </s:a>
- </li>
- </s:if>
- <s:else>
- <li class="even">
- <s:a href="CommodityAction!findCommodityByClass.action?commodityClassId=%{#classes.commodityClassId} ">
- <s:property value="#classes.commodityClassName"/>
- </s:a>
- </li>
- </s:else>
- </s:iterator>
- </ul><br/></td>
- </tr>
- <!--<tr>
- <td align=center class="title_box">论坛公告
- </td></tr>
- <tr>
- <td align=center ><marquee height=120 direction="up" scrollamount=3 onmouseover="this.stop()" onmouseout="this.start()">
- <h3>网上商城系统开通了,欢迎广大客户光临</h3></marquee>
- </td></tr>
- --></table>
- </td>
-
- <td class="center_content" width=100% height=400px>
- <iframe class=main_iframe id=frmright name="frmright" frameborder=0 scrolling=auto src="product.jsp">
- </iframe>
- </td>
-
- <td class="right_content"><table>
- <tr>
- <td class="shopping_cart"><table>
- <tr><td class="cart_title">购物车 </td>
- </tr>
- <tr><td class="cart_icon">
- <a href="showCar.jsp" title="">
- <img src="images/shoppingcart.png" alt="" title="" width="48" height="48" border="0" /></a>
- </td>
- </tr></table>
- </td></tr>
- <tr><td> <c:if test="${empty sessionScope.user.username}">
- <form action="UserAction!login.action" name="form" method="post" >
- <div class="title_box">用户登录</div>
- <div class="border_box">
- <p>用户名:<input id="username" name="user.username" type="text" style="width:110px"/></p>
- <p>密 码:<input id="password" name="user.password" type="password" style="width:110px"/></p>
- <p> <input name="提交" type="submit" value="登录" /><input name="重置" type="reset" value="重置" />
- </p>
- <p align="center"> [<a href="register.jsp">新用户注册</a>] [<a href="findPass.jsp" >忘记密码</a>]</p>
-
- </div> </form> </c:if>
- <c:if test="${!empty sessionScope.user.username}">
- <div class="title_box">用户信息</div>
- <div class="border_box">
- <br/>
- <p>欢迎登陆:${sessionScope.user.username}</p><br/>
- <p> [<a href="OrderFormAction!findOrderFormByUserName.action?orderForm.username=${sessionScope.user.username}">我的订单</a>] [<a href="updatePass.jsp" >修改密码</a>] </p>
- <p> [<a href="userInfo.jsp">个人信息</a>] [<a href="UserAction!logout.action" onclick="return confirm('确定要退出吗?')" >退出系统</a>] </p>
- </div>
- </c:if>
-
- </td>
- </tr>
- </table></td>
- </tr>
- </table>
-
-
- <div class="footer" align="center"><br/>© | XXXX | 版权所有 | 网上商城系统<br/><a href="admin/login.jsp">后台管理</a></div>
-
- </div>
- </s:if>
- <s:else><s:action name="GoIndexAction" executeResult="true"></s:action>
- </s:else>
- </body>
- </html>
- package cn.itbaizhan.action;
-
- import java.util.Collection;
- import java.util.Map;
-
- import javax.annotation.Resource;
-
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Component;
-
- import cn.itbaizhan.po.User;
- import cn.itbaizhan.service.UserService;
-
- import com.opensymphony.xwork2.ActionContext;
- import com.opensymphony.xwork2.ActionSupport;
-
- //import com.cds.po.Department;
- //import com.cds.po.Role;
-
- //import com.cds.service.DepartmentService;
- //import com.cds.service.RoleService;
-
- @SuppressWarnings("serial")
- @Component("userAction")
- @Scope("prototype")//多例,每个请求生成一个新的action
- public class UserAction extends ActionSupport {
- private User user;
- //要调用UserService的方法,所以要声明,让spring把其实现类注入。@Resource 默认按 byName 自动注入
- @Resource(name="userServiceImpl")
- UserService service;
- public UserService getService() {
- return service;
- }
-
- public void setService(UserService service) {
- this.service = service;
- }
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
-
- @Override
- public String execute() throws Exception {
- // 不要直接访问数据库,应该访问业务逻辑层service,而service去访问DAO,dao去访问数据库
- String username= user.getUsername();
- System.out.println(username);
-
- User user = service.findUserByName(username);
- if(user==null){
- this.service.save(this.user);
- return "success";
- }
- else{
- return "error";
- }
- }
- //列表
- @SuppressWarnings("unchecked")
- public String listUser(){
- Map request = (Map) ActionContext.getContext().get("request");
-
- request.put("listUsers", service.findAllUsers());
- System.out.println("listUsers"+service.findAllUsers().size());
- return "listUser";
- }
-
- //查询
- @SuppressWarnings("unchecked")
- public String queryUser(){
- String username= user.getUsername();
- System.out.println(username);
- String name= user.getName();
-
- User user=this.service.queryUser(username);
- System.out.println("user:"+user);
- Map request = (Map) ActionContext.getContext().get("request");
-
- request.put("queryUser", user);
- //System.out.println("queryUser"+service.queryUser().size());
-
- return "queryUser";
- }
-
- public String deleteUser(){
- this.service.delete(user);
- return "deleteUser";
- }
- public String findUserById(){
- user = this.service.findUserById(user.getUserId());
- return "findUser";
- }
-
- public String updateUser(){
-
- this.service.update(user);
- System.out.println("user:"+user.getUserId());
- ActionContext.getContext().put("updatemessage", "您的信息已经更新!");
- return "updateUser";
- }
-
- @SuppressWarnings("unchecked")
- public String addUser(){
- Map request = (Map) ActionContext.getContext().get("request");
-
- return "adduser";
- }
- //个人密码跳转
- /*public String updatePassword(){
- return "updatePassword";
- }
- */
- public String findUser()
- {
- String username= user.getUsername();
- System.out.println("username:"+username);
- String name= user.getName();
- System.out.println("name:"+name);
- String sex= user.getSex();
- System.out.println("sex:"+sex);
- String post= user.getPost();
- System.out.println("post:"+post);
- String address= user.getAddress();
- System.out.println("address:"+address);
- String phone= user.getPhone();
- System.out.println("phone:"+phone);
- String email= user.getEmail();
- System.out.println("email:"+email);
-
- User user=this.service.findUserByinfo(username, name,sex,phone, post, address, email);
- System.out.println("user:"+user);
-
- if(user==null){
- ActionContext.getContext().put("findUsernull", "没有该用户信息!");
- return "findUsernull";
- }else{
- ActionContext.getContext().getSession().put("findUser", user);
-
- return "findUser";
- }
-
- }
- //修改密码
- public String upPass()
- {
- this.service.update(user);
- System.out.println("user:"+user.getUserId());
- ActionContext.getContext().put("upPass", "您的密码已经修改!");
- return "upPass";
- }
- //重设密码
- public String updatePass()
- {
- this.service.update(user);
- System.out.println("user:"+user.getUserId());
- ActionContext.getContext().put("updatePass", "您的密码已经更改!");
- return "updatePass";
- }
- //用户注册验证
- public String register()
- {
-
- String username= user.getUsername();
- System.out.println(username);
-
- User user = service.findUserByName(username);
- System.out.println("name:"+username+",user:"+user);
- if(user == null){
- ActionContext.getContext().put("regmessage", username+"可以注册");
- return "regsuccess";
- }else{
- ActionContext.getContext().put("regmessage", username+"已经被注册");
- return "regerror";
- }
- }
- //用户登录
- public String login(){
- String username= user.getUsername();
- System.out.println(username);
- String password=user.getPassword();
-
- User user = service.getUserByLoginNameAndPassword(username,password);
- System.out.print("name:"+username+"pass"+password+"user"+user);
- if(user == null){
- ActionContext.getContext().put("message", "用户名或密码错误");
- return "login";
- }else{
- ActionContext.getContext().getSession().put("user", user);
- return "index";
- }
- }
- //用户退出
- public String logout(){
- ActionContext.getContext().getSession().clear();
- return "logout";
- }
-
- }
- package cn.itbaizhan.service;
-
- import java.util.List;
- import java.util.Map;
-
- import cn.itbaizhan.po.User;
-
- public interface UserService {
- // 和UserDao的方法一样,可以封装,因为这边只是调用
- public void save(User user);
- public void delete(User id);
- public User findUserById(int id);
- public List<User> findAllUsers();
- public void update(User user);
- //public void initPassword(User user);
- public User getUserByLoginNameAndPassword(String username, String password);
- public User findUserByName(String username);
- public User queryUser(String username);
- public User findUserByinfo(String username, String name, String sex,
- String phone, String post, String address, String email);
- }
- package cn.itbaizhan.service.impl;
-
- import java.util.List;
-
- import javax.annotation.Resource;
-
- import org.springframework.stereotype.Component;
-
- import cn.itbaizhan.dao.UserDao;
- import cn.itbaizhan.po.User;
- import cn.itbaizhan.service.UserService;
- //把类交给spring管理(如同配置bean节点)此类受spring事务管理
- @Component("userServiceImpl")
- public class UserServiceImpl implements UserService {
- //要调用dao层代码,所以要有UserDao的对象,把其实现类靠spring注入
- @Resource(name="userDaoImpl")
- private UserDao userDao;
- public UserDao getUserDao() {
- return userDao;
- }
-
- public void setUserDao(UserDao userDao) {
- this.userDao = userDao;
- }
-
- public void delete(User user) {
- this.userDao.delete(user);
-
- }
- public List<User> findAllUsers() {
- return this.userDao.findAllUsers();
- }
- public User findUserById(int id) {
-
- return this.userDao.findUserById(id);
- }
-
- public void save(User user) {
- this.userDao.save(user);
-
- }
-
- public void update(User user) {
- this.userDao.update(user);
- }
-
- public User getUserByLoginNameAndPassword(String username, String password) {
-
- return this.userDao.getUserByLoginNameAndPassword(username,password);
- }
-
- public User findUserByName(String username) {
-
- return this.userDao.findUserByName(username);
- }
-
- public User queryUser(String username) {
- return this.userDao.queryUser(username);
- }
-
- public User findUserByinfo(String username, String name, String sex,
- String phone, String post, String address, String email) {
-
- return this.userDao.findUserByinfo(username, name,sex,phone, post, address, email);
- }
-
-
- }
- package cn.itbaizhan.dao;
-
- import java.util.List;
-
- import cn.itbaizhan.po.User;
-
- public interface UserDao {
- public void save(User user);
- public void delete(User user);
- public User findUserById(int id);
- public User findUserByinfo(String username, String name, String sex,String phone,
- String post,String address, String email);
- public List<User> findAllUsers();
- public void update(User user);
- //public void initPassword(User user);
- public User getUserByLoginNameAndPassword(String username, String password);
- public User findUserByName(String username);
- public User queryUser(String username);
-
- }
- package cn.itbaizhan.dao.impl;
-
- import java.util.List;
-
- import javax.annotation.Resource;
-
-
-
-
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import org.springframework.stereotype.Component;
-
- import cn.itbaizhan.dao.UserDao;
- import cn.itbaizhan.po.User;
- @Component("userDaoImpl")
- public class UserDaoImpl implements UserDao {
- //使用spring对Hibernate的模版 HibernateTemplate
- @Resource(name="hibernateTemplate")
- private HibernateTemplate hibernateTemplate;
-
- public void delete(User user) {
- hibernateTemplate.delete(user);
- }
- @SuppressWarnings("unchecked")//不检查,当编码可能存在警告时,比如安全警告,可以用它来消除
- public List<User> findAllUsers() {
- String hql = "from User";
- return (List<User>)hibernateTemplate.find(hql);
- }
-
- public User findUserById(int id) {
- User user = (User)hibernateTemplate.get(User.class, id);
- return user;
- }
-
- public void save(User user) {
- System.out.println(user);
- hibernateTemplate.save(user);
- }
-
- public void update(User user) {
- hibernateTemplate.update(user);
-
- }
- public HibernateTemplate getHibernateTmeplate() {
- return hibernateTemplate;
- }
- public void setHibernateTmeplate(HibernateTemplate hibernateTemplate) {
- this.hibernateTemplate = hibernateTemplate;
- }
-
- //获取用户
- public User getUserByLoginNameAndPassword(String username, String password) {
-
- System.out.println("用户名"+username);
-
-
- return (User) hibernateTemplate.getSessionFactory().openSession().createQuery(
- "from User u where u.username=? and u.password=?").setParameter(0, username).setParameter(1, password).uniqueResult();
- }
- public User findUserByName(String username) {
- System.out.println("用户名:"+username);
-
- return (User) hibernateTemplate.getSessionFactory().openSession().createQuery(
- "from User u where u.username=?").setParameter(0, username).uniqueResult();
-
-
- }
-
- public User queryUser(String username) {
-
- //String hql = "from User";
- return (User)hibernateTemplate.getSessionFactory().openSession().createQuery(
- "from User u where u.username=? ").setParameter(
- 0, username).uniqueResult();
-
- }
- public User findUserByinfo(String username, String name, String sex,
- String phone, String post, String address, String email) {
- return (User)hibernateTemplate.getSessionFactory().openSession().createQuery(
- "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(
- 0, username).setParameter(1,name).setParameter(2,sex).setParameter(3,phone).setParameter(4,post).setParameter(5,address).setParameter(6,email).uniqueResult();
-
- }
-
-
-
- }
2、添加购物车
3、提交订单
4、订单付款
5、我的订单
6、后台管理首页
7、后端管理主页
8、商品管理
9、订单管理
10、用户管理
11、系统管理
1、程序源码包
2、数据库初始化脚本文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。