基于javaweb+mysql的jsp+servlet秒杀与竞价拍卖系统(java+jsp+bootstrap+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet秒杀与竞价拍卖系统(java+jsp+bootstrap+jquery+mysql)
项目介绍
基于B2C的网上拍卖系统主要用于帮助人们应用互联网方便快捷买到自己所中意的商品,并参与到秒杀与竞拍当中。
主要功能包括: 1.前台模块 (1)普通用户登录/注册。 (2)分类查看商品(普通商品与促销商品) (3)查看商品详细信息 (4)查看秒杀商品 (5)查看竞拍商品 (6)将商品加入购物车 (7)购买,结算功能 (8)留言 2.后台模块 (1)修改密码 (2)商品管理: 编辑/删除 设置/取消促销 (3)秒杀商品:设置/取消秒杀 (4)竞拍商品:设置/取消竞拍 (5)订单管理:查看订单 (6)留言管理:查看/删除留言
环境需要
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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 5.7版本;
技术栈
- 后端:Servlet 2. 前端:JSP+bootstrap+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 将项目中resources/ioc/dao.js配置文件中的数据库配置改为自己的配置; 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行; 4.项目访问路径: 前台:http://localhost:8080/sale 后台:http://localhost:8080/sale/user/adminlogin
if(list.get(0).getAdmin()==1){
request.setAttribute("user", list.get(0));
request.getSession().setAttribute("user", list.get(0));
return new JspView("jsp.admin.index");
}else{
request.setAttribute("msg", "无管理员权限");
return new JspView("jsp.admin.login");
}
}
}
/**
* adminlogout
* @param request
* @return
*/
@At("/adminlogout")
public View adminlogout(HttpServletRequest request){
request.getSession().setAttribute("user", null);
return new JspView("jsp.admin.login");
}
/**
* logout
* @param request
* @return
*/
@At("/logout")
public View logout(HttpServletRequest request){
request.getSession().setAttribute("user", null);
//新品上市
List<Product> newlist = productService.findNewProduct();
request.setAttribute("newlist", newlist);
//促销
List<Product> cxlist = productService.findCxProduct();
request.setAttribute("cxlist", cxlist);
return new JspView("jsp.index");
}
/**
* 跳转到修改密码
* @param request
* @return
*/
@At("/tochangePsd")
public View tochangePsd(HttpServletRequest request){
return new JspView("jsp.changePsd");
}
/**
* 跳转到admin修改密码
* @param request
* @return
*/
@At("/toAdminChangePsd")
public View toAdminChangePsd(HttpServletRequest request){
return new JspView("jsp.admin.changePsd");
pagerNum = "1";
}
List<Product> list = productService.findListSpike();
request.setAttribute("count", list.size());
request.setAttribute("maxPager", PagerUtil.getMaxPager(list.size()));
list = (List<Product>) PagerUtil.getPager(list,
Integer.parseInt(pagerNum));
request.setAttribute("list", list);
request.setAttribute("pagerNum", pagerNum);
return new JspView("jsp.admin.product.spikelist");
}
@At("/toszms")
public View toszms(HttpServletRequest request) {
String id = request.getParameter("id");
Product product = productService.findProductById(Integer.parseInt(id));
request.setAttribute("product", product);
return new JspView("jsp.admin.product.szms");
}
@At("/szms")
public View szms(HttpServletRequest request) {
String id = request.getParameter("id");
Product product = productService.findProductById(Integer.parseInt(id));
String price = request.getParameter("price");
String count = request.getParameter("count");
String time = request.getParameter("time");
if (count == null) {
count = "0";
}
product.setSfms(1);
product.setMscount(Integer.parseInt(count));
product.setMsprice(price);
product.setMsdate(time);
int i = productService.editProduct(product);
if (i == 1) {
request.setAttribute("msg", "修改成功");
} else {
request.setAttribute("msg", "修改失败");
return new JspView("jsp.changePsd");
}
}else{
request.setAttribute("msg", "原密码错误");
return new JspView("jsp.changePsd");
}
}
/**
* admin修改密码
* @param request
* @return
*/
@At("/adminChangePsd")
public View adminChangePsd(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
String newpsd = request.getParameter("newpsd");
user.setPassword(newpsd);
int i = userService.editUser(user);
if(i==1){
request.setAttribute("msg", "密码修改成功");
return new JspView("jsp.admin.changePsd");
}else{
request.setAttribute("msg", "密码修改失败");
return new JspView("jsp.admin.changePsd");
}
}
}
@SuppressWarnings("unchecked")
@IocBean
@At("/message")
public class MessageAction {
@Inject("refer:messageService")
request.setAttribute("msg", "error");
}
return new JspView("jsp.register");
}
/**
* login
*/
@At("/login")
public View login(HttpServletRequest request){
String username = request.getParameter("username");
String password = request.getParameter("password");
List<User> list = userService.findUserByNameAndPsd(username, password);
//新品上市
List<Product> newlist = productService.findNewProduct();
request.setAttribute("newlist", newlist);
//促销
List<Product> cxlist = productService.findCxProduct();
request.setAttribute("cxlist", cxlist);
if(list.size()!=1){
request.setAttribute("msg", "error");
return new JspView("jsp.login");
}else{
request.setAttribute("user", list.get(0));
request.getSession().setAttribute("user", list.get(0));
return new JspView("jsp.index");
}
}
/**
* Adminlogin
*/
@At("/adminlogin")
public View adminlogin(HttpServletRequest request){
String username = request.getParameter("username");
String password = request.getParameter("password");
//如果直接请求该方法,就跳转到后台登录页面
if(username==null&&password==null){
return new JspView("jsp.admin.login");
}
orderService.deleteOrder(Integer.parseInt(id));
//**
User user = (User)request.getSession().getAttribute("user");
List<Order> list = orderService.getCartList(user.getId());
request.setAttribute("list", list);
int sumprice = 0;
for(int i=0;i<list.size();i++){
list.get(i).setUser(userService.findUserById(list.get(i).getUserid()));
list.get(i).setProduct(productService.findProductById(list.get(i).getProid()));
if(sumprice==0){
sumprice = Integer.parseInt(list.get(i).getPrice());
}else{
sumprice += Integer.parseInt(list.get(i).getPrice());
}
}
request.setAttribute("sumprice", sumprice);
request.setAttribute("count", list.size());
return new JspView("jsp.cart");
}
/**
* 到结算页面
*/
@At("/tocheckout")
public View tocheckout(HttpServletRequest request){
String price = request.getParameter("price");
request.setAttribute("price", price);
return new JspView("jsp.checkout");
}
/**
* 到付款界面
*/
@At("/topay")
public View topay(HttpServletRequest request){
String price = request.getParameter("price");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String tel = request.getParameter("tel");
String address = request.getParameter("address");
String senddept = request.getParameter("senddept");
User user = (User)request.getSession().getAttribute("user");
List<Order> list = orderService.getCartList(user.getId());
Order order = new Order();
for(int i=0;i<list.size();i++){
order = list.get(i);
order.setAddress(address);
order.setDate(df.format(new Date()));
order.setSenddept(senddept);
list = (List<Product>) PagerUtil.getPager(list,
Integer.parseInt(pagerNum));
request.setAttribute("list", list);
request.setAttribute("pagerNum", pagerNum);
return new JspView("jsp.admin.product.spikelist");
}
@At("/qxms")
public View qxms(HttpServletRequest request) {
String id = request.getParameter("id");
Product product = productService.findProductById(Integer.parseInt(id));
product.setSfms(0);
product.setNewprice(null);
product.setMscount(0);
product.setMsprice(null);
product.setMsdate(null);
int i = productService.editProduct(product);
if (i == 1) {
request.setAttribute("msg", "修改成功");
} else {
request.setAttribute("msg", "修改失败");
}
// ****
String pagerNum = request.getParameter("pagerNum");
if (pagerNum == null) {
pagerNum = "1";
}
List<Product> list = productService.findListSpike();
request.setAttribute("count", list.size());
request.setAttribute("maxPager", PagerUtil.getMaxPager(list.size()));
list = (List<Product>) PagerUtil.getPager(list,
Integer.parseInt(pagerNum));
request.setAttribute("list", list);
request.setAttribute("pagerNum", pagerNum);
return new JspView("jsp.admin.product.spikelist");
}
// 秒杀结束**************************************************
// 竞拍开始**************************************************
/**
* 竞拍列表
*
* @param request
* @return
*/
@At("/promolist")
public View promolist(HttpServletRequest request) {
String pagerNum = request.getParameter("pagerNum");
c.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(product.getMsdate()));
}catch (ParseException e) {
e.printStackTrace();
}
long current_time=System.currentTimeMillis();
long end_time=c.getTimeInMillis();
long time=end_time-current_time;
request.setAttribute("time", time/1000);
return new JspView("jsp.msdetail");
}
/**
* 跳转到竞拍产品详细
* @param request
* @return
*/
@At("/tojpDetail")
public View tojpDetail(HttpServletRequest request){
String id = request.getParameter("id");
Product product = productService.findProductById(Integer.parseInt(id));
//促销
List<Product> cxlist = productService.findCxProduct();
request.setAttribute("cxlist", cxlist);
request.setAttribute("product", product);
Calendar c =Calendar.getInstance();
try{
c.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(product.getJpdate()));
}catch (ParseException e) {
e.printStackTrace();
}
long current_time=System.currentTimeMillis();
long end_time=c.getTimeInMillis();
long time=end_time-current_time;
request.setAttribute("time", time/1000);
return new JspView("jsp.jpdetail");
}
/**
* 跳转到购物车
* @param request
* @return
*/
@At("/toCart")
public View toCart(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
List<Order> list = orderService.getCartList(user.getId());
request.setAttribute("list", list);
int sumprice = 0;
for(int i=0;i<list.size();i++){
list.get(i).setUser(userService.findUserById(list.get(i).getUserid()));
return new JspView("jsp.index");
}
/**
* 跳转到修改密码
* @param request
* @return
*/
@At("/tochangePsd")
public View tochangePsd(HttpServletRequest request){
return new JspView("jsp.changePsd");
}
/**
* 跳转到admin修改密码
* @param request
* @return
*/
@At("/toAdminChangePsd")
public View toAdminChangePsd(HttpServletRequest request){
return new JspView("jsp.admin.changePsd");
}
/**
* 修改密码
* @param request
* @return
*/
@At("/changePsd")
public View changePsd(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
String oldpsd = request.getParameter("oldpsd");
String newpsd = request.getParameter("newpsd");
String cpsd = request.getParameter("cpsd");
if(oldpsd.equals(user.getPassword())){
if(newpsd.equals(cpsd)){
user.setPassword(newpsd);
int i = userService.editUser(user);
if(i==1){
request.setAttribute("msg", "密码修改成功");
return new JspView("jsp.changePsd");
}else{
request.setAttribute("msg", "密码修改失败");
return new JspView("jsp.changePsd");
}
}else{
request.setAttribute("msg", "新密码两次输入不一致");
return new JspView("jsp.changePsd");
}
}else{
request.setAttribute("msg", "原密码错误");
return new JspView("jsp.changePsd");
}
* add pro
*
* @param request
* @return
* @throws IOException
*/
@At("/add")
@AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" })
public View add(HttpServletRequest request, @Param("file") TempFile file,
@Param("name") String name, @Param("price") String price,
@Param("content") String content) throws IOException {
Product product = new Product();
product.setName(name);
product.setPrice(price);
product.setContent(content);
// 保存图片开始
File f = file.getFile();
String filename = f.getName();
int address = filename.lastIndexOf(".");
String type = filename.substring(address + 1, filename.length());
String date = new SimpleDateFormat("yyyyMMddHHmmssSS").format(Calendar
.getInstance().getTime());
//String yp = "D:\\file\\";
String yp = request.getServletContext().getRealPath("/");
//String changePath = yp + date + "." + type;// 实际保存路径
String changePath = yp + "\\resources\\file\\" + date + "." + type;// 实际保存路径
//String changePath = yp + "/resources/file/" + date + "." + type;// mac系统 实际保存路径
File desFile = new File(changePath);
File pck = new File(yp);
// 检查目录
if (!pck.exists()) {
pck.mkdirs();
}
desFile.createNewFile();
FileOutputStream out = new FileOutputStream(desFile);
FileInputStream in = new FileInputStream(f);
byte[] stream = new byte[in.available()];
in.read(stream);
out.write(stream);
out.close();
in.close();
// 保存到硬盘结束
// //
String imgPath = "resources/file/" + date + "." + type;
product.setImg(imgPath);
product = productService.addProduct(product);
if (product != null) {
*/
@At("/pay")
public View pay(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
List<Order> list = orderService.getCartList(user.getId());
Order order = new Order();
Product product = new Product();
for(int i=0;i<list.size();i++){
order = list.get(i);
order.setSffk(1);
order.setVisible(1);
orderService.editOrder(order);
product = productService.findProductById(order.getProid());
if(product.getSfms()==1){//如果是秒杀,秒杀数量-1
product.setMscount(product.getMscount()-1);
productService.editProduct(product);
}
}
request.setAttribute("msg", "付款成功");
//新品上市
List<Product> newlist = productService.findNewProduct();
request.setAttribute("newlist", newlist);
//促销
List<Product> cxlist = productService.findCxProduct();
request.setAttribute("cxlist", cxlist);
return new JspView("jsp.index");
}
/**
*
* @param request
* @return
*/
@At("/toOrderList")
public View toOrderList(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
List<Order> list = orderService.getOrderList(user.getId());
for(int i=0;i<list.size();i++){
list.get(i).setUser(userService.findUserById(list.get(i).getUserid()));
list.get(i).setProduct(productService.findProductById(list.get(i).getProid()));
}
request.setAttribute("list", list);
return new JspView("jsp.orderlist");
}
@At("/addprice")
public View addprice(HttpServletRequest request){
@IocBean
@At("/index")
public class IndexAction {
@Inject("refer:productService")
private ProductService productService;
@Inject("refer:orderService")
private OrderService orderService;
@Inject("refer:userService")
private UserService userService;
/**
* 跳转到首页
* @param request
* @return
*/
@At("/toIndex")
public View toIndex(HttpServletRequest request){
//新品上市
List<Product> newlist = productService.findNewProduct();
request.setAttribute("newlist", newlist);
//促销
}
List<Product> list = productService.findListPromo();
request.setAttribute("count", list.size());
request.setAttribute("maxPager", PagerUtil.getMaxPager(list.size()));
list = (List<Product>) PagerUtil.getPager(list,
Integer.parseInt(pagerNum));
request.setAttribute("list", list);
request.setAttribute("pagerNum", pagerNum);
return new JspView("jsp.admin.product.promolist");
}
// 竞拍结束**************************************************
}
@IocBean
@At("/order")
public class OrderAction {
@Inject("refer:orderService")
private OrderService orderService;
@Inject("refer:productService")
FileOutputStream out = new FileOutputStream(desFile);
FileInputStream in = new FileInputStream(f);
byte[] stream = new byte[in.available()];
in.read(stream);
out.write(stream);
out.close();
in.close();
// 保存到硬盘结束
// //
String imgPath = "resources/file"+date+"."+type;
product.setImg(changePath);
int i = productService.editProduct(product);
if (i == 1) {
request.setAttribute("msg", "修改成功");
} else {
request.setAttribute("msg", "修改失败");
}
}
// ****
String pagerNum = request.getParameter("pagerNum");
if (pagerNum == null) {
pagerNum = "1";
}
List<Product> list = productService.findListProduct();
request.setAttribute("count", list.size());
request.setAttribute("maxPager", PagerUtil.getMaxPager(list.size()));
list = (List<Product>) PagerUtil.getPager(list,
Integer.parseInt(pagerNum));
request.setAttribute("list", list);
request.setAttribute("pagerNum", pagerNum);
return new JspView("jsp.admin.product.list");
}
@At("/toszcx")
public View toszcx(HttpServletRequest request) {
String id = request.getParameter("id");
Product product = productService.findProductById(Integer.parseInt(id));
request.setAttribute("product", product);
return new JspView("jsp.admin.product.szcx");
}
@At("/szcx")
public View szcx(HttpServletRequest request) {
String id = request.getParameter("id");
String newprice = request.getParameter("newprice");
Product product = productService.findProductById(Integer.parseInt(id));
product.setNewprice(newprice);
public View changePsd(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
String oldpsd = request.getParameter("oldpsd");
String newpsd = request.getParameter("newpsd");
String cpsd = request.getParameter("cpsd");
if(oldpsd.equals(user.getPassword())){
if(newpsd.equals(cpsd)){
user.setPassword(newpsd);
int i = userService.editUser(user);
if(i==1){
request.setAttribute("msg", "密码修改成功");
return new JspView("jsp.changePsd");
}else{
request.setAttribute("msg", "密码修改失败");
return new JspView("jsp.changePsd");
}
}else{
request.setAttribute("msg", "新密码两次输入不一致");
return new JspView("jsp.changePsd");
}
}else{
request.setAttribute("msg", "原密码错误");
return new JspView("jsp.changePsd");
}
}
/**
* admin修改密码
* @param request
* @return
*/
@At("/adminChangePsd")
public View adminChangePsd(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
String newpsd = request.getParameter("newpsd");
user.setPassword(newpsd);
int i = userService.editUser(user);
if(i==1){
//促销
List<Product> cxlist = productService.findCxProduct();
request.setAttribute("cxlist", cxlist);
return new JspView("jsp.index");
}
/**
* 跳转到修改密码
* @param request
* @return
*/
@At("/tochangePsd")
public View tochangePsd(HttpServletRequest request){
return new JspView("jsp.changePsd");
}
/**
* 跳转到admin修改密码
* @param request
* @return
*/
@At("/toAdminChangePsd")
public View toAdminChangePsd(HttpServletRequest request){
return new JspView("jsp.admin.changePsd");
}
/**
* 修改密码
* @param request
* @return
*/
@At("/changePsd")
public View changePsd(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
String oldpsd = request.getParameter("oldpsd");
String newpsd = request.getParameter("newpsd");
String cpsd = request.getParameter("cpsd");
if(oldpsd.equals(user.getPassword())){
if(newpsd.equals(cpsd)){
user.setPassword(newpsd);
int i = userService.editUser(user);
if(i==1){
request.setAttribute("msg", "密码修改成功");
return new JspView("jsp.changePsd");
}else{
request.setAttribute("msg", "密码修改失败");
return new JspView("jsp.changePsd");
}
@SuppressWarnings("unchecked")
@IocBean
@At("/message")
public class MessageAction {
@Inject("refer:messageService")
private MessageService messageService;
/**
* 留言列表
* @param request
* @return
*/
@At("/list")
public View tologin(HttpServletRequest request){
String pagerNum = request.getParameter("pagerNum");
if(pagerNum==null){
pagerNum = "1";
}
List<Message> list = messageService.findListMessage();
list = (List<Message>) PagerUtil.getPager(list, Integer.parseInt(pagerNum));
request.setAttribute("list", list);
request.setAttribute("count", list.size());
request.setAttribute("maxPager", list.size()/10+1);
request.setAttribute("pagerNum", pagerNum);
return new JspView("jsp.admin.message");
}
/**
* add message
* @param request
* @return
*/
@At("/add")
*/
@At("/adminChangePsd")
public View adminChangePsd(HttpServletRequest request){
User user = (User)request.getSession().getAttribute("user");
String newpsd = request.getParameter("newpsd");
user.setPassword(newpsd);
int i = userService.editUser(user);
if(i==1){
request.setAttribute("msg", "密码修改成功");
return new JspView("jsp.admin.changePsd");
}else{
request.setAttribute("msg", "密码修改失败");
return new JspView("jsp.admin.changePsd");
}
}
}
@SuppressWarnings("unchecked")
@IocBean
@At("/message")
public class MessageAction {
@Inject("refer:messageService")
private MessageService messageService;
/**
* 留言列表
* @param request
* @return
*/
@At("/list")
public View tologin(HttpServletRequest request){
String pagerNum = request.getParameter("pagerNum");
if(pagerNum==null){
Product product = new Product();
product.setName(name);
product.setPrice(price);
product.setContent(content);
// 保存图片开始
File f = file.getFile();
String filename = f.getName();
int address = filename.lastIndexOf(".");
String type = filename.substring(address + 1, filename.length());
String date = new SimpleDateFormat("yyyyMMddHHmmssSS").format(Calendar
.getInstance().getTime());
//String yp = "D:\\file\\";
String yp = request.getServletContext().getRealPath("/");
//String changePath = yp + date + "." + type;// 实际保存路径
String changePath = yp + "\\resources\\file\\" + date + "." + type;// 实际保存路径
//String changePath = yp + "/resources/file/" + date + "." + type;// mac系统 实际保存路径
File desFile = new File(changePath);
File pck = new File(yp);
// 检查目录
if (!pck.exists()) {
pck.mkdirs();
}
desFile.createNewFile();
FileOutputStream out = new FileOutputStream(desFile);
FileInputStream in = new FileInputStream(f);
byte[] stream = new byte[in.available()];
in.read(stream);
out.write(stream);
out.close();
in.close();
// 保存到硬盘结束
// //
String imgPath = "resources/file/" + date + "." + type;
product.setImg(imgPath);
product = productService.addProduct(product);
if (product != null) {
request.setAttribute("msg", "添加成功");
} else {
request.setAttribute("msg", "添加失败");
}
// ****
String pagerNum = request.getParameter("pagerNum");
if (pagerNum == null) {
pagerNum = "1";
}
List<Product> list = productService.findListProduct();
request.setAttribute("count", list.size());
request.setAttribute("maxPager", PagerUtil.getMaxPager(list.size()));
list = (List<Product>) PagerUtil.getPager(list,
Integer.parseInt(pagerNum));