基于javaweb+mysql的jsp+servlet网上花店商城系统(java+jsp+servlert+mysql+ajax)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet网上花店商城系统(java+jsp+servlert+mysql+ajax)
一、项目简述
功能: 一套完整的网上花店商场系统,系统支持前台会员的注册 登陆系统留言,花朵的品种选择,详情浏览,加入购物 车,购买花朵等;后台支持管理员的花朵种类添加,花朵 详情的添加修改,用户管理,留言管理,商场新闻管理等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP + Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload等等。
ids.remove(0);
}
//System.out.println(!ids.contains(Integer.parseInt(id)));
if(id!=null&&(!ids.contains(Integer.parseInt(id)))){
ids.add(Integer.parseInt(id));
}
session.setAttribute("ids", ids);
ids = (ArrayList<Integer>) session.getAttribute("ids");
if(ids!=null){
ArrayList<EASYBUY_PRODUCT> lastlylist = EASYBUY_PRODUCTDao.selectById(ids);
req.setAttribute("lastlylist", lastlylist);
}
//查询商品
EASYBUY_PRODUCT p = null;
if(id!=null){
p = EASYBUY_PRODUCTDao.selectById(Integer.parseInt(id));
}
req.setAttribute("p", p);
req.getRequestDispatcher("product-view.jsp").forward(req, resp);
}
}
public class LoginServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String username=req.getParameter("userName");
String passWord=req.getParameter("passWord");
String veryCode=req.getParameter("veryCode");
resp.setContentType("text/html;charset=utf-8");
try {
su.upload();
} catch (SmartUploadException e) {
e.printStackTrace();
}
Files fs = su.getFiles();//获得所有文件
File f = fs.getFile(0);//获得上传的文件
String fname = f.getFileName();//获得文件名
try {
su.save("images/product");//保存图片到指定位置
} catch (SmartUploadException e) {
e.printStackTrace();
}
Request req1 = su.getRequest();
String pname = req1.getParameter("productName");
String id = req1.getParameter("parentId");
String price = req1.getParameter("productPrice");
String desc = req1.getParameter("productDesc");
String stock = req1.getParameter("productStock");
EASYBUY_PRODUCT p = null;
if(price!=null && stock!=null && id!=null){
p = new EASYBUY_PRODUCT(0, pname, desc,
Integer.parseInt(price),
Integer.parseInt(stock),
Integer.parseInt(id.split("-")[0]),
Integer.parseInt(id.split("-")[1]),
fname);
}
int count = 0;
if(p!=null){
count = EASYBUY_PRODUCTDao.insert(p);
}
req.getRequestDispatcher("productSelect").forward(req, resp);
}
}
req.setAttribute("page", page);
// 跳
req.getRequestDispatcher("guestbook.jsp").forward(req,resp);
}
}
}
public class SelectDD extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
//查询分类数据
ArrayList<EASYBUY_PRODUCT_CATEGORY> flist = EASYBUY_PRODUCT_CATEGORYDao.selectFather();
req.setAttribute("flist", flist);
ArrayList<EASYBUY_PRODUCT_CATEGORY> clist = EASYBUY_PRODUCT_CATEGORYDao.selectChild();
req.setAttribute("clist", clist);
ArrayList<EASYBUY_PRODUCT> tlist = EASYBUY_PRODUCTDao.selectAllByT();
req.setAttribute("tlist", tlist);
public class UpManage extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
int id=Integer.parseInt(request.getParameter("orderId"));
String name=request.getParameter("name");
String replyContent=request.getParameter("replyContent");
String Content=request.getParameter("Content");
Date date=new Date();
System.out.println(Content);
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String replyTime=sdf.format(date);
EASYBUY_COMMENT comment=new EASYBUY_COMMENT(id,Content,replyTime,replyContent,replyTime,name);
//System.out.println(id+"--"+content+"--"+replyTime+"--"+replyContent+"--"+name);
comment.setEC_ID(id);
int num=EASYBUY_COMMENTDao.update(comment);
if(num>0){
response.sendRedirect("manage-result.jsp");
}else{
}
}
}
public class SelManage extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//编码
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
int page=1; //当前页数
int pagesize=6;//每页行数
String spage=req.getParameter("page");
if(spage!=null){ //如果页面上传递了页数,将当前页数改变掉
page=Integer.parseInt(spage);
}
//查出总页数
ArrayList<EASYBUY_COMMENT> list=EASYBUY_COMMENTDao.selPage(page, pagesize);
int max_page=EASYBUY_COMMENTDao.getMax(pagesize);
if(list.size()>0&&max_page>0){
req.setAttribute("list", list);
//把总页数传递给guestbook.jsp 使用
req.setAttribute("max_page", max_page);
//把当前页数传递给guestbook.jsp使用
req.setAttribute("page", page);
// 跳
req.getRequestDispatcher("guestbook.jsp").forward(req,resp);
}else{
resp.getWriter().print("还没有留言信息哦!");
}
}
}
//订单表数据的查询
desc,
Integer.parseInt(price),
Integer.parseInt(stock),
Integer.parseInt(pid.split("-")[0]),
Integer.parseInt(pid.split("-")[1]),
fname);
int count = 0;
if(p!=null){
count = EASYBUY_PRODUCTDao.update(p);
}
req.getRequestDispatcher("productSelect").forward(req, resp);
}
}
public class DoProductAddServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
SmartUpload su = new SmartUpload();
su.initialize(this.getServletConfig(), req, resp);
try {
su.upload();
} catch (SmartUploadException e) {
e.printStackTrace();
}
Files fs = su.getFiles();//获得所有文件
File f = fs.getFile(0);//获得上传的文件
String fname = f.getFileName();//获得文件名
String price = req1.getParameter("productPrice");
String desc = req1.getParameter("productDesc");
String stock = req1.getParameter("productStock");
EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(Integer.parseInt(id),
pname,
desc,
Integer.parseInt(price),
Integer.parseInt(stock),
Integer.parseInt(pid.split("-")[0]),
Integer.parseInt(pid.split("-")[1]),
fname);
int count = 0;
if(p!=null){
count = EASYBUY_PRODUCTDao.update(p);
}
req.getRequestDispatcher("productSelect").forward(req, resp);
}
}
public class DoProductAddServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
SmartUpload su = new SmartUpload();
su.initialize(this.getServletConfig(), req, resp);
try {
su.upload();
} catch (SmartUploadException e) {
e.printStackTrace();
}
public class DoProductUpdateServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
SmartUpload su = new SmartUpload();
su.initialize(this.getServletConfig(), req, resp);
try {
su.upload();
} catch (SmartUploadException e) {
e.printStackTrace();
}
Files fs = su.getFiles();//获得所有文件
File f = fs.getFile(0);//获得上传的文件
String fname = f.getFileName();//获得文件名
try {
su.save("images/product");//保存图片到指定位置
} catch (SmartUploadException e) {
e.printStackTrace();
}
}
String uid = user.getEU_USER_ID();
int valid = 1;
eb_shop sp = new eb_shop(0, p.getEP_FILE_NAME(), p.getEP_NAME(), p.getEP_PRICE(), Integer.parseInt(count), p.getEP_STOCK(), p.getEP_ID(), uid, valid);
int epid=p.getEP_ID();
ESDao.insert(sp);
resp.sendRedirect("selectProductView?id="+epid);
//req.getRequestDispatcher("selectProductView?id=").forward(req, resp);
}
}
public class ShopAddServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// es_id NUMBER primary key not null,--id
// es_ep_file_name NVARCHAR2(30),--图片名称
// es_ep_name NVARCHAR2(30),--商品名
// es_ep_price NUMBER,--商品单价
// es_eod_quantity NUMBER,--购买数量
// es_ep_stock NUMBER,--商品库存
// es_ep_id NUMBER,--商品id
// es_EU_USER_ID NVARCHAR2(30),--用户id
// es_valid NUMBER --是否结账,1未结账,2已结账
EASYBUY_PRODUCT p = null;
String pid = req.getParameter("id");
String count = req.getParameter("count");
if(pid!=null){
p = EASYBUY_PRODUCTDao.selectById(Integer.parseInt(pid));
}
resp.setContentType("text/html;charset=utf-8");
PrintWriter out = resp.getWriter();
HttpSession session = req.getSession();
EASYBUY_USER user=(EASYBUY_USER)session.getAttribute("name");
public class SelectProductViewServlet extends HttpServlet {
@SuppressWarnings("unchecked")
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ArrayList<EASYBUY_PRODUCT_CATEGORY> flist = EASYBUY_PRODUCT_CATEGORYDao.selectFather();
req.setAttribute("flist", flist);
ArrayList<EASYBUY_PRODUCT_CATEGORY> clist = EASYBUY_PRODUCT_CATEGORYDao.selectChild();
req.setAttribute("clist", clist);
String id = req.getParameter("id");
HttpSession session = req.getSession();
//查询最近浏览的商品
ArrayList<Integer> ids = (ArrayList<Integer>)session.getAttribute("ids");
if(ids==null){
ids = new ArrayList<Integer>();
}
if(ids.size()>=5){
ids.remove(0);
}
//System.out.println(!ids.contains(Integer.parseInt(id)));
if(id!=null&&(!ids.contains(Integer.parseInt(id)))){
ids.add(Integer.parseInt(id));
}
session.setAttribute("ids", ids);
ids = (ArrayList<Integer>) session.getAttribute("ids");
if(ids!=null){
ArrayList<EASYBUY_PRODUCT> lastlylist = EASYBUY_PRODUCTDao.selectById(ids);
req.setAttribute("lastlylist", lastlylist);
}
//查询商品
EASYBUY_PRODUCT p = null;
if(id!=null){
p = EASYBUY_PRODUCTDao.selectById(Integer.parseInt(id));
}
req.setAttribute("p", p);
req.getRequestDispatcher("product-view.jsp").forward(req, resp);
}
}
public class DoProductAddServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
SmartUpload su = new SmartUpload();
su.initialize(this.getServletConfig(), req, resp);
try {
su.upload();
} catch (SmartUploadException e) {
e.printStackTrace();
}
Files fs = su.getFiles();//获得所有文件
File f = fs.getFile(0);//获得上传的文件
String fname = f.getFileName();//获得文件名
try {
su.save("images/product");//保存图片到指定位置
} catch (SmartUploadException e) {
e.printStackTrace();
}
Request req1 = su.getRequest();
String pname = req1.getParameter("productName");
String id = req1.getParameter("parentId");
req.setAttribute("lastlylist", lastlylist);
}
req.getRequestDispatcher("index.jsp").forward(req, resp);
}
}
public class UserNumServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
int width=120;
int height=60;
BufferedImage img=new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
Graphics2D g=img.createGraphics();
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, width, height);
g.setColor(Color.YELLOW);
Random rand=new Random();
for (int i = 0; i < 15; i++) {
int x1=rand.nextInt(width);
int y1=rand.nextInt(width);
int x2=rand.nextInt(width);
int y2=rand.nextInt(width);
g.drawLine(x1, y1, x2, y2);
}
Font f=new Font("Times New Roman",Font.BOLD,50);
g.setFont(f);
int red=0,green=0,blue=0;
Graphics2D g=img.createGraphics();
g.setColor(Color.LIGHT_GRAY);
g.fillRect(0, 0, width, height);
g.setColor(Color.YELLOW);
Random rand=new Random();
for (int i = 0; i < 15; i++) {
int x1=rand.nextInt(width);
int y1=rand.nextInt(width);
int x2=rand.nextInt(width);
int y2=rand.nextInt(width);
g.drawLine(x1, y1, x2, y2);
}
Font f=new Font("Times New Roman",Font.BOLD,50);
g.setFont(f);
int red=0,green=0,blue=0;
String code="";
for (int i = 0; i < 4; i++) {
red=rand.nextInt(255);
green=rand.nextInt(255);
blue=rand.nextInt(255);
Color c=new Color(red,green,blue);
g.setColor(c);
int num=rand.nextInt(10);
code+=num;
g.drawString(num+"", i*20+20, 49);
}
HttpSession session=req.getSession();
session.setAttribute("syscode", code);
ServletOutputStream out=resp.getOutputStream();
ImageIO.write(img, "jpg", out);
}
}
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
SmartUpload su = new SmartUpload();
su.initialize(this.getServletConfig(), req, resp);
try {
su.upload();
} catch (SmartUploadException e) {
e.printStackTrace();
}
Files fs = su.getFiles();//获得所有文件
File f = fs.getFile(0);//获得上传的文件
String fname = f.getFileName();//获得文件名
try {
su.save("images/product");//保存图片到指定位置
} catch (SmartUploadException e) {
e.printStackTrace();
}
Request req1 = su.getRequest();
String pname = req1.getParameter("productName");
String id = req1.getParameter("parentId");
String price = req1.getParameter("productPrice");
String desc = req1.getParameter("productDesc");
String stock = req1.getParameter("productStock");
EASYBUY_PRODUCT p = null;
if(price!=null && stock!=null && id!=null){
p = new EASYBUY_PRODUCT(0, pname, desc,
Integer.parseInt(price),
Integer.parseInt(stock),
Integer.parseInt(id.split("-")[0]),
Integer.parseInt(id.split("-")[1]),
fname);
}
int count = 0;
if(p!=null){
count = EASYBUY_PRODUCTDao.insert(p);
}
req.getRequestDispatcher("productSelect").forward(req, resp);
}
}
public class SelallServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
int page=1; //当前页数
int pagesize=6;//每页行数
String spage=req.getParameter("page");
ArrayList<EASYBUY_PRODUCT_CATEGORY> flist = EASYBUY_PRODUCT_CATEGORYDao.selectFather();
req.setAttribute("flist", flist);
ArrayList<EASYBUY_PRODUCT_CATEGORY> clist = EASYBUY_PRODUCT_CATEGORYDao.selectChild();
req.setAttribute("clist", clist);
if(spage!=null){ //如果页面上传递了页数,将当前页数改变掉
page=Integer.parseInt(spage);
}
//查出总页数
ArrayList<EASYBUY_COMMENT> list=EASYBUY_COMMENTDao.selPage(page, pagesize);
int max_page=EASYBUY_COMMENTDao.getMax(pagesize);
if(list.size()>0&&max_page>0){
req.setAttribute("list", list);
//把总页数传递给guestbook.jsp 使用
req.setAttribute("max_page", max_page);
//把当前页数传递给guestbook.jsp使用
req.setAttribute("page", page);
// 跳
req.getRequestDispatcher("guestbook.jsp").forward(req,resp);
}else{
req.setAttribute("list", list);
//把总页数传递给guestbook.jsp 使用
req.setAttribute("max_page", max_page);
//把当前页数传递给guestbook.jsp使用
req.setAttribute("page", page);
// 跳
req.getRequestDispatcher("guestbook.jsp").forward(req,resp);
}
}
}
ArrayList<eb_shop> list=ESDao.getShop(id);
req.setAttribute("shoplist",list);
//req.getRequestDispatcher("shopping.jsp").forward(req, resp);
}else{
out.print("<script>");
out.print("alert('请先登录');");
out.print("location.href='login.jsp';");
out.print("</script>");
out.close();
return;
}
String uid = user.getEU_USER_ID();
int valid = 1;
eb_shop sp = new eb_shop(0, p.getEP_FILE_NAME(), p.getEP_NAME(), p.getEP_PRICE(), Integer.parseInt(count), p.getEP_STOCK(), p.getEP_ID(), uid, valid);
ESDao.insert(sp);
resp.sendRedirect("ShopSelect");
//req.getRequestDispatcher("ShopSelect").forward(req, resp);
}
}
public class SelallServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
int page=1; //当前页数
int pagesize=6;//每页行数
String spage=req.getParameter("page");
ArrayList<EASYBUY_PRODUCT_CATEGORY> flist = EASYBUY_PRODUCT_CATEGORYDao.selectFather();
req.setAttribute("flist", flist);
ArrayList<EASYBUY_PRODUCT_CATEGORY> clist = EASYBUY_PRODUCT_CATEGORYDao.selectChild();
req.setAttribute("clist", clist);
if(spage!=null){ //如果页面上传递了页数,将当前页数改变掉
page=Integer.parseInt(spage);
}
public class SelectProductViewServlet extends HttpServlet {
@SuppressWarnings("unchecked")
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ArrayList<EASYBUY_PRODUCT_CATEGORY> flist = EASYBUY_PRODUCT_CATEGORYDao.selectFather();
req.setAttribute("flist", flist);
ArrayList<EASYBUY_PRODUCT_CATEGORY> clist = EASYBUY_PRODUCT_CATEGORYDao.selectChild();
req.setAttribute("clist", clist);
String id = req.getParameter("id");
HttpSession session = req.getSession();
//查询最近浏览的商品
ArrayList<Integer> ids = (ArrayList<Integer>)session.getAttribute("ids");
if(ids==null){
ids = new ArrayList<Integer>();
}
if(ids.size()>=5){
ids.remove(0);
}
//System.out.println(!ids.contains(Integer.parseInt(id)));
if(id!=null&&(!ids.contains(Integer.parseInt(id)))){
ids.add(Integer.parseInt(id));
}
session.setAttribute("ids", ids);
ids = (ArrayList<Integer>) session.getAttribute("ids");
if(ids!=null){
ArrayList<EASYBUY_PRODUCT> lastlylist = EASYBUY_PRODUCTDao.selectById(ids);
req.setAttribute("lastlylist", lastlylist);
}
//查询商品
EASYBUY_PRODUCT p = null;
if(id!=null){
p = EASYBUY_PRODUCTDao.selectById(Integer.parseInt(id));
}