jsp + servlet online ordering system (front desk, backend) based on javaweb + mysql (java + jsp + servlet + mysql + dbutil + tomcat)
Private message Source code acquisition and debugging communication
Operating environment
Java≥8, MySQL≥5.7, Tomcat≥8
development tools
eclipse/idea/myeclipse/sts, etc. can be configured to run
Be applicable
Course design, major assignments, graduation projects, project exercises, learning demonstrations, etc.
Function Description
Backstage: login, category management, dish management, member management, order management, message management, etc.
Front desk: log in, register, view dishes, purchase, leave messages
front desk
Backstage
technical framework
JSP Servlet MySQL DBUtil Tomcat JavaScript CSS jstl
JSP + Servlet online ordering system (front desk, backend) based on javaweb + mysql (java + jsp + servlet + mysql + dbutil + tomcat)
public class order_servlet extends HttpServlet {<!-- --> public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {<!-- --> String type=req.getParameter("type"); \t\t if(type.endsWith("orderMana")) {<!-- --> orderMana(req, res);//Order management } if(type.endsWith("orderDel")) {<!-- --> orderDel(req, res);//Delete order } if(type.endsWith("orderShouli")) {<!-- --> orderShouli(req, res);//Accept orders } \t\t if(type.endsWith("huifuAdd")) {<!-- --> huifuAdd(req, res);//Add reply } } \t public void orderMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {<!-- --> List orderList=new ArrayList(); String sql="select * from t_order order by zhuangtai desc"; Object[] params={<!-- -->}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- --> Torder order=new Torder(); \t\t\t\t order.setId(rs.getString("id")); order.setBianhao(rs.getString("bianhao")); order.setShijian(rs.getString("shijian")); order.setZhuangtai(rs.getString("zhuangtai")); order.setHuifu(rs.getString("huifu")); order.setSonghuodizhi(rs.getString("songhuodizhi")); order.setFukuanfangshi(rs.getString("fukuanfangshi")); order.setJine(rs.getInt("jine"));
mydb.closed(); } \t\t\t } \t\t \t\t if(userType==1)//Member login {<!-- --> String sql="select * from t_user where loginname=? and loginpw=? and del='no'"; Object[] params={<!-- -->userName,userPw}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); boolean mark=(rs==null||!rs.next()?false:true); if(mark==false) {<!-- --> result="no"; } if(mark==true) {<!-- --> result="yes"; \t\t\t\t\t Tuser user=new Tuser(); \t\t\t\t\t user.setId(rs.getString("id")); user.setLoginname(rs.getString("loginname")); user.setLoginpw(rs.getString("loginpw")); user.setName(rs.getString("name")); \t\t\t\t\t user.setDel(rs.getString("del")); \t\t\t\t\t WebContext ctx = WebContextFactory.get(); HttpSession session=ctx.getSession(); \t\t\t\t\t session.setAttribute("userType", 1); session.setAttribute("user", user); Cart cart=new Cart(); session.setAttribute("cart", cart); } rs.close(); } catch(Exception e) {<!-- --> e.printStackTrace(); } mydb.closed();
TorderItem orderItem = (TorderItem) it.next();//Get the next object, convert it into a TorderItem object, and give the TorderItem object orderItem \t\t\t String id=String.valueOf(new Date().getTime());//Get the number ID String order_id=order.getId();//Get the order ID String goods_id=orderItem.getGoods().getId(); int goods_quantity=orderItem.getGoods_quantity(); liuService.saveOrderItem(id, order_id, goods_id, goods_quantity);//Save id, order_id, goods_id, goods_quantity \t\t\t } \t\t cart.getItems().clear(); //Clear the shopping cart session.setAttribute("cart", cart); \t\t req.setAttribute("order", order); req.getRequestDispatcher("site/order/orderSubmit.jsp").forward(req, res);//Jump to this interface } \t \t public void myorder(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//My Order {<!-- --> HttpSession session=req.getSession(); Tuser user=(Tuser)session.getAttribute("user"); \t\t req.setAttribute("orderList", liuService.orderList(user.getId()));//Set the attributes of orderList req.getRequestDispatcher("site/order/myorder.jsp").forward(req, res); } \t public void orderDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//Order Details {<!-- --> String order_id=req.getParameter("order_id"); System.out.println(order_id + "DD");//Output order_idDD req.setAttribute("orderItemList", liuService.orderItemList(order_id)); req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res); } \t \t public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) //Jump to the next interface {<!-- --> RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI); try {<!-- --> dispatch.forward(request, response); return; } catch (ServletException e) {<!-- --> e.printStackTrace();
} \t\t cart.getItems().clear(); //Clear the shopping cart session.setAttribute("cart", cart); \t\t req.setAttribute("order", order); req.getRequestDispatcher("site/order/orderSubmit.jsp").forward(req, res);//Jump to this interface } \t \t public void myorder(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//My Order {<!-- --> HttpSession session=req.getSession(); Tuser user=(Tuser)session.getAttribute("user"); \t\t req.setAttribute("orderList", liuService.orderList(user.getId()));//Set the attributes of orderList req.getRequestDispatcher("site/order/myorder.jsp").forward(req, res); } \t public void orderDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//Order Details {<!-- --> String order_id=req.getParameter("order_id"); System.out.println(order_id + "DD");//Output order_idDD req.setAttribute("orderItemList", liuService.orderItemList(order_id)); req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res); } \t \t public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) //Jump to the next interface {<!-- --> RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI); try {<!-- --> dispatch.forward(request, response); return; }
catch(Exception e) {<!-- --> e.printStackTrace(); } mydb.closed(); \t\t req.setAttribute("userList", userList); req.getRequestDispatcher("admin/user/userMana.jsp").forward(req, res); } \t \t \t public void userDel(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {<!-- --> String id=req.getParameter("id"); \t\t String sql="update t_user set del='yes' where id=?"; Object[] params={<!-- -->id}; DB mydb=new DB(); mydb.doPstm(sql, params); mydb.closed(); \t\t req.setAttribute("msg", "User information deleted"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res); } \t \t public void userDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {<!-- --> String id=req.getParameter("id"); \t\t List userList=new ArrayList(); String sql="select * from t_user where id=?"; Object[] params={<!-- -->id}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- --> Tuser user=new Tuser(); \t\t\t\t user.setId(rs.getString("id")); user.setLoginname(rs.getString("loginname")); user.setLoginpw(rs.getString("loginpw")); user.setLoginpw(rs.getString("loginpw")); user.setName(rs.getString("name")); \t\t\t\t userList.add(user); } rs.close(); }
public class loginService {<!-- --> public String login(String userName,String userPw,int userType) {<!-- --> String result="no"; \t\t if(userType==0)//System administrator login {<!-- --> String sql="select * from t_admin where userName=? and userPw=?"; Object[] params={<!-- -->userName,userPw}; DB mydb=new DB(); mydb.doPstm(sql, params); try {<!-- --> ResultSet rs=mydb.getRs(); boolean mark=(rs==null||!rs.next()?false:true);//If the result set is empty, return false, if the result set is not empty, return true if(mark==false) {<!-- --> result="no"; } else {<!-- --> result="yes"; TAdmin admin=new TAdmin(); admin.setUserId(rs.getInt("userId")); admin.setUserName(rs.getString("userName")); admin.setUserPw(rs.getString("userPw")); WebContext ctx = WebContextFactory.get(); //Get the WebContext object ctx HttpSession session=ctx.getSession(); session.setAttribute("userType", 0); session.setAttribute("admin", admin); } rs.close(); } catch (SQLException e) {<!-- --> System.out.println("Login failed!"); e.printStackTrace(); } finally {<!-- --> mydb.closed(); } \t\t\t
order.setHuifu(""); \t\t order.setSonghuodizhi(songhuodizhi); order.setFukuanfangshi(fukuanfangshi); order.setJine(cart.getTotalPrice());//Set the total amount order.setUser_id(user.getId()); \t\t liuService.saveOrder(order); \t\t for (Iterator it = cart.getItems().values().iterator(); it.hasNext();) //Create the iterator object it, the value is the value of the product quantity, if there is something after the iterator, execute the loop {<!-- --> TorderItem orderItem = (TorderItem) it.next();//Get the next object, convert it into a TorderItem object, and give the TorderItem object orderItem \t\t\t String id=String.valueOf(new Date().getTime());//Get the number ID String order_id=order.getId();//Get the order ID String goods_id=orderItem.getGoods().getId(); int goods_quantity=orderItem.getGoods_quantity(); liuService.saveOrderItem(id, order_id, goods_id, goods_quantity);//Save id, order_id, goods_id, goods_quantity \t\t\t } \t\t cart.getItems().clear(); //Clear the shopping cart session.setAttribute("cart", cart); \t\t req.setAttribute("order", order); req.getRequestDispatcher("site/order/orderSubmit.jsp").forward(req, res);//Jump to this interface } \t \t public void myorder(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//My Order {<!-- --> HttpSession session=req.getSession(); Tuser user=(Tuser)session.getAttribute("user"); \t\t req.setAttribute("orderList", liuService.orderList(user.getId()));//Set the attributes of orderList req.getRequestDispatcher("site/order/myorder.jsp").forward(req, res); } \t public void orderDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//Order Details {<!-- --> String order_id=req.getParameter("order_id"); System.out.println(order_id + "DD");//Output order_idDD req.setAttribute("orderItemList", liuService.orderItemList(order_id)); req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res); }
public class order_servlet extends HttpServlet {<!-- --> public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {<!-- --> String type=req.getParameter("type"); \t\t if(type.endsWith("orderMana")) {<!-- --> orderMana(req, res);//Order management } if(type.endsWith("orderDel")) {<!-- --> orderDel(req, res);//Delete order } if(type.endsWith("orderShouli")) {<!-- --> orderShouli(req, res);//Accept orders } \t\t if(type.endsWith("huifuAdd")) {<!-- --> huifuAdd(req, res);//Add reply } } \t public void orderMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {<!-- --> List orderList=new ArrayList(); String sql="select * from t_order order by zhuangtai desc"; Object[] params={<!-- -->}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- --> Torder order=new Torder(); \t\t\t\t
Object[] params={<!-- -->}; DB mydb=new DB(); mydb.doPstm(sql, params); mydb.closed(); \t\t req.setAttribute("msg", "Message information deleted"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res); } \t \t public void liuyanHuifu(HttpServletRequest req,HttpServletResponse res) {<!-- --> String huifu=req.getParameter("huifu"); String huifushi=new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); int id=Integer.parseInt(req.getParameter("id")); \t\t String sql="update t_liuyan set huifu=?,huifushi=? where id=?"; Object[] params={<!-- -->huifu,huifushi,id}; DB mydb=new DB(); mydb.doPstm(sql, params); mydb.closed(); \t\t req.setAttribute("msg", "Reply completed"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res); } public void liuyanAll(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {<!-- --> List liuyanList=new ArrayList(); String sql="select * from t_liuyan order by liuyanshi"; Object[] params={<!-- -->}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- -->
e.printStackTrace(); } mydb.closed(); \t\t req.setAttribute("catelogList", catelogList); req.getRequestDispatcher("admin/catelog/catelogMana.jsp").forward(req, res); } \t \t \t public void catelogDel(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException //Dish category deleted successfully {<!-- --> String sql="update t_catelog set del='yes' where id=" + req.getParameter("id"); Object[] params={<!-- -->}; DB mydb=new DB(); mydb.doPstm(sql, params); mydb.closed(); \t\t req.setAttribute("msg", "Operation successful"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res); } \t \t public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) //Jump to next page {<!-- --> RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI); try {<!-- --> dispatch.forward(request, response); return; } catch (ServletException e) {<!-- --> e.printStackTrace(); } catch (IOException e) {<!-- --> \t\t\t e.printStackTrace();
} \t \t public void goodsMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException //Manage products and set various attributes of products {<!-- --> List goodsList=new ArrayList(); String sql="select * from t_goods where del='no'"; Object[] params={<!-- -->}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- --> Tgoods goods=new Tgoods(); \t\t\t\t goods.setId(rs.getString("id")); goods.setCatelog_id(rs.getString("catelog_id")); goods.setBianhao(rs.getString("bianhao")); \t\t\t\t goods.setMingcheng(rs.getString("mingcheng")); goods.setJieshao(rs.getString("jieshao")); goods.setFujian(rs.getString("fujian")); \t\t\t\t goods.setShichangjia(rs.getInt("shichangjia")); goods.setTejia(rs.getInt("tejia")); goods.setDel(rs.getString("del")); \t\t\t\t goodsList.add(goods); } rs.close(); } catch(Exception e) {<!-- --> e.printStackTrace(); } mydb.closed(); \t\t req.setAttribute("goodsList", goodsList); req.getRequestDispatcher("admin/goods/goodsMana.jsp").forward(req, res); } \t \t \t public void goodsDel(HttpServletRequest req,HttpServletResponse res) //delete product {<!-- --> String id=req.getParameter("id"); String sql="update t_goods set del='yes' where id=" + id; Object[] params={<!-- -->};
HttpSession session=req.getSession(); Tuser user=(Tuser)session.getAttribute("user"); \t\t req.setAttribute("orderList", liuService.orderList(user.getId()));//Set the attributes of orderList req.getRequestDispatcher("site/order/myorder.jsp").forward(req, res); } \t public void orderDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException \t//Order Details {<!-- --> String order_id=req.getParameter("order_id"); System.out.println(order_id + "DD");//Output order_idDD req.setAttribute("orderItemList", liuService.orderItemList(order_id)); req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res); } \t \t public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) //Jump to the next interface {<!-- --> RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI); try {<!-- --> dispatch.forward(request, response); return; } catch (ServletException e) {<!-- --> e.printStackTrace(); } catch (IOException e) {<!-- --> \t\t\t e.printStackTrace(); } } public void init(ServletConfig config) throws ServletException //Initialize Servlet configuration {<!-- --> super.init(config); } \t public void destroy() {<!-- --> \t\t } }
req.getRequestDispatcher("site/order/orderDetail.jsp").forward(req, res); } \t \t public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) //Jump to the next interface {<!-- --> RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI); try {<!-- --> dispatch.forward(request, response); return; } catch (ServletException e) {<!-- --> e.printStackTrace(); } catch (IOException e) {<!-- --> \t\t\t e.printStackTrace(); } } public void init(ServletConfig config) throws ServletException //Initialize Servlet configuration {<!-- --> super.init(config); } \t public void destroy() {<!-- --> \t\t } }
public class xinyong_servlet extends HttpServlet {<!-- --> public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {<!-- --> String type=req.getParameter("type"); \t\t if(type.endsWith("xinyongAdd")) {<!-- --> xinyongAdd(req, res);//Credit addition } if(type.endsWith("xinyongMana")) {<!-- --> xinyongMana(req, res);//Credit management } if(type.endsWith("xinyongDel")) {<!-- --> xinyongDel(req, res);//Credit deletion } } \t public void xinyongAdd(HttpServletRequest req,HttpServletResponse res) {<!-- --> String id=String.valueOf(new Date().getTime()); String shuxing=req.getParameter("shuxing").trim(); String neirong=req.getParameter("neirong").trim(); String shijian=req.getParameter("shijian").trim(); \t\t String user_id=req.getParameter("user_id").trim(); \t\t String sql="insert into t_xinyong(id,shuxing,neirong,shijian,user_id) values(?,?,?,?,?)"; Object[] params={<!-- -->id,shuxing,neirong,shijian,user_id}; DB mydb=new DB(); mydb.doPstm(sql, params); mydb.closed(); \t\t req.setAttribute("msg", "Operation successful"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res);
mydb.closed(); \t\t req.setAttribute("msg", "Operation successful"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res); } \t \t public void goodsMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException //Manage products and set various attributes of products {<!-- --> List goodsList=new ArrayList(); String sql="select * from t_goods where del='no'"; Object[] params={<!-- -->}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- --> Tgoods goods=new Tgoods(); \t\t\t\t goods.setId(rs.getString("id")); goods.setCatelog_id(rs.getString("catelog_id")); goods.setBianhao(rs.getString("bianhao")); \t\t\t\t goods.setMingcheng(rs.getString("mingcheng")); goods.setJieshao(rs.getString("jieshao")); goods.setFujian(rs.getString("fujian")); \t\t\t\t goods.setShichangjia(rs.getInt("shichangjia")); goods.setTejia(rs.getInt("tejia")); goods.setDel(rs.getString("del")); \t\t\t\t goodsList.add(goods); } rs.close(); } catch(Exception e) {<!-- --> e.printStackTrace(); } mydb.closed(); \t\t req.setAttribute("goodsList", goodsList); req.getRequestDispatcher("admin/goods/goodsMana.jsp").forward(req, res);
String sql="insert into t_liuyan(neirong,liuyanshi,user_id,huifu,huifushi) values(?,?,?,?,?)"; Object[] params={<!-- -->neirong,liuyanshi,user_id,huifu,huifushi}; DB mydb=new DB(); mydb.doPstm(sql, params); mydb.closed(); \t\t req.setAttribute("msg", "Message completed"); String targetURL = "/common/msg.jsp"; dispatch(targetURL, req, res); } \t public void liuyanMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException {<!-- --> List liuyanList=new ArrayList(); String sql="select * from t_liuyan order by liuyanshi"; Object[] params={<!-- -->}; DB mydb=new DB(); try {<!-- --> mydb.doPstm(sql, params); ResultSet rs=mydb.getRs(); while(rs.next()) {<!-- --> TLiuyan liuyan=new TLiuyan(); \t\t\t\t liuyan.setId(rs.getInt("id")); liuyan.setNeirong(rs.getString("neirong")); liuyan.setLiuyanshi(rs.getString("liuyanshi")); liuyan.setUser_id(rs.getString("user_id")); \t\t\t\t liuyan.setHuifu(rs.getString("huifu")); liuyan.setHuifushi(rs.getString("huifushi")); \t\t\t liuyanList.add(liuyan); } rs.close(); } catch(Exception e) {<!-- --> e.printStackTrace(); } mydb.closed();
{<!-- --> e.printStackTrace(); } catch (IOException e) {<!-- --> \t\t\t e.printStackTrace(); } } public void init(ServletConfig config) throws ServletException {<!-- --> super.init(config); } \t public void destroy() {<!-- --> \t\t } } public class buy_servlet extends HttpServlet {<!-- --> \t public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException //request object req, response object res