基于javaweb+mysql的jsp+servlet网上图书商城(java+servlet+jsp+mysql)

基于javaweb+mysql的jsp+servlet网上图书商城(java+servlet+jsp+mysql)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的JSP+Servlet网上图书商城(java+servlet+jsp+mysql)

后台管理员:

http://localhost:8080/adminjsps/login.jsp

admin 123456

前台用户:

http://localhost:8080

user1 123456

user2 123456

项目采用MVC三层架构,使用(JSP + Sevlvet + JavaBean)技术

前台功能模块有:登录注册(校验)

加入购物车

订单管理(下订单和确认收货或者取消)

后台功能模块:图书分级管理(一级和二级)

图书管理(图书增删改查)

订单管理

用到的技术

开发环境:MyEclipse, Tomcat, Mysql

后台技术: JSP, Servlet, JavaBean

前端技术: JSP, CSS, HTML5, CSS3, jQuery, Javascript

			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		String author = req.getParameter("author");
		PageBean<Book> pb = bookService.findByAuthor(author, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/adminjsps/admin/book/list.jsp";
	}
	
	//按出版社查询
	public String findByPress(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		String press = req.getParameter("press");
		PageBean<Book> pb = bookService.findByPress(press, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/adminjsps/admin/book/list.jsp";
	}

	// 按图名查
	public String findByBname(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		String bname = req.getParameter("bname");
		PageBean<Book> pb = bookService.findByBname(bname, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/adminjsps/admin/book/list.jsp";
	}
	
	//多条件组合查询
	public String findByCombination(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		Book criteria = CommonUtils.toBean(req.getParameterMap(), Book.class);
		PageBean<Book> pb = bookService.findByCombination(criteria, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/adminjsps/admin/book/list.jsp";
	}
}

		} else if(loginpass.length() < 3 || loginpass.length() > 20) {
			errors.put("loginpass", "密码长度必须在3~20之间!");
		}
		// 3. 确认密码校验
		String reloginpass = formUser.getReloginpass();
		if(reloginpass == null || reloginpass.trim().isEmpty()) {
			errors.put("reloginpass", "确认密码不能为空!");
		} else if(!reloginpass.equals(loginpass)) {
			errors.put("reloginpass", "两次输入不一致!");
		}
		// 4. 校验email
		String email = formUser.getEmail();
		if(email == null || email.trim().isEmpty()) {
			errors.put("email", "Email不能为空!");
		} else if(!email.matches("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$")) {
			errors.put("email", "Email格式错误!");
		} else if(!userService.ajaxValidateEmail(email)) {
			errors.put("email", "Email已被注册!");
		}
		//5. 验证码校验
		String verifyCode = formUser.getVerifyCode();
		String vcode = (String) session.getAttribute("vCode");
		if(verifyCode == null || verifyCode.trim().isEmpty()) {
			errors.put("verifyCode", "验证码不能为空!");
		} else if(!verifyCode.equalsIgnoreCase(vcode)) {
			errors.put("verifyCode", "验证码错误!");
		}
		return errors;
	}
	

	
	//修改密码 
	public String updatePassword(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);
		User user = (User)req.getSession().getAttribute("sessionUser");
		if(user == null) {
			req.setAttribute("msg", "您还没有登录!");
			return "f:/jsps/user/login.jsp";
		}
		try {
		resp.getWriter().print(b);
		return null;
	}
	
	//图片验证码是否正确校验
	public String ajaxValidateVerifyCode(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String verifyCode = req.getParameter("verifyCode");
		String vcode = (String) req.getSession().getAttribute("vCode");
		boolean b = verifyCode.equalsIgnoreCase(vcode);
		resp.getWriter().print(b);
		return null;
	}

	//注册功能
	public String regist(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);//拿到表单数据
		//校验之, 如果校验失败,保存错误信息,返回到regist.jsp显示
		Map<String,String> errors = validateRegist(formUser, req.getSession());
		if(errors.size() > 0) {
			req.setAttribute("form", formUser);
			req.setAttribute("errors", errors);
			return "f:/frontpages/user/register.jsp";
		}
		//使用service完成业务
		userService.regist(formUser);
		//保存成功信息,转发到msg.jsp显示!
		req.setAttribute("code", "success");
		req.setAttribute("msg", "注册成功!");
		return "f:/frontpages/msg.jsp";
	}
	
	//注册校验	 * 对表单的字段进行逐个校验,如果有错误,使用当前字段名称为key,错误信息为value,保存到map中
	private Map<String,String> validateRegist(User formUser, HttpSession session) {
		Map<String,String> errors = new HashMap<String,String>();
		//1. 校验登录名
		String loginname = formUser.getLoginname();
		if(loginname == null || loginname.trim().isEmpty()) {
			errors.put("loginname", "用户名不能为空!");
		} else if(loginname.length() < 3 || loginname.length() > 20) {
			errors.put("loginname", "用户名长度必须在3~20之间!");
		} else if(!userService.ajaxValidateLoginname(loginname)) {
			errors.put("loginname", "用户名已被注册!");
		}
		
		//2. 校验登录密码
		String loginpass = formUser.getLoginpass();
		if(loginpass == null || loginpass.trim().isEmpty()) {
			errors.put("loginpass", "密码不能为空!");
		} else if(loginpass.length() < 3 || loginpass.length() > 20) {
        super(request);
        this.request = request;
        this.charset = charset;
    }

    public String getParameter(String name) {
        String value = this.request.getParameter(name);
        if (value == null) {
            return null;
        } else {
            try {
                return new String(value.getBytes("ISO-8859-1"), this.charset);
            } catch (UnsupportedEncodingException var4) {
                throw new RuntimeException(var4);
            }
        }
    }

    public Map getParameterMap() {
        Map<String, String[]> map = this.request.getParameterMap();
        if (map == null) {
            return map;
        } else {
            Iterator var3 = map.keySet().iterator();

            while(var3.hasNext()) {
                String key = (String)var3.next();
                String[] values = (String[])map.get(key);

                for(int i = 0; i < values.length; ++i) {
                    try {
                        values[i] = new String(values[i].getBytes("ISO-8859-1"), this.charset);
                    } catch (UnsupportedEncodingException var7) {
                        throw new RuntimeException(var7);
                    }
                }
            }

            return map;
        }
    }

    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);

                    try {
                        values[i] = new String(values[i].getBytes("ISO-8859-1"), this.charset);
                    } catch (UnsupportedEncodingException var7) {
                        throw new RuntimeException(var7);
                    }
                }
            }

            return map;
        }
    }

    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);

        for(int i = 0; i < values.length; ++i) {
            try {
                values[i] = new String(values[i].getBytes("ISO-8859-1"), this.charset);
            } catch (UnsupportedEncodingException var5) {
                throw new RuntimeException(var5);
            }
        }

        return values;
    }
}

public class EntranceFilter implements Filter {
    private String charset = "UTF-8";

    public EntranceFilter() { }

    public void destroy() { }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest)request;
        if (((HttpServletRequest)req).getMethod().equalsIgnoreCase("GET")) {//如果是get方法时
            if (!(req instanceof RightRequest)) {
                req = new RightRequest((HttpServletRequest)req, charset);//将请求变成GetRequest类型
		order.setTotal(total.doubleValue());//设置总计

		List<OrderItem> orderItemList = new ArrayList<OrderItem>();
		for(CartItem cartItem : cartItemList) {
			OrderItem orderItem = new OrderItem();
			orderItem.setOrderItemId(CommonUtils.uuid());//设置主键
			orderItem.setQuantity(cartItem.getQuantity());
			orderItem.setSubtotal(cartItem.getSubtotal());
			orderItem.setBook(cartItem.getBook());
			orderItem.setOrder(order);
			orderItemList.add(orderItem);
		}
		order.setOrderItemList(orderItemList);
		orderService.createOrder(order);
		cartItemService.batchDelete(cartItemIds);
		req.setAttribute("order", order);
		return "f:/frontpages/order/ordersucc.jsp";
	}
}

public class AdminCategoryServlet extends MyServlet {
	private CategoryService categoryService = new CategoryService();
	private BookService bookService = new BookService();
	
	// 查询所有分类
	public String findAll(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setAttribute("parents", categoryService.findAll());
		return "f:/adminjsps/admin/category/list.jsp";
	}
	
	//添加一级分类
	public String addParent(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Category parent = CommonUtils.toBean(req.getParameterMap(), Category.class);
		parent.setCid(CommonUtils.uuid());//设置cid
		categoryService.add(parent);
		return findAll(req, resp);
	}
	

public class AdminBookServlet extends MyServlet {

	private BookService bookService = new BookService();
	private CategoryService categoryService = new CategoryService();

	
	// 删除图书
	public String delete(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String bid = req.getParameter("bid");
		Book book = bookService.load(bid);
		String savepath = this.getServletContext().getRealPath("/");//获取真实的路径
		//new File(savepath, book.getImage_w()).delete();//删除文件
		//new File(savepath, book.getImage_b()).delete();//删除文件
		bookService.delete(bid);//删除数据库的记录
		req.setAttribute("code", "success");
		req.setAttribute("msg", "删除成功");
		return "f:/frontpages/msg1.jsp";
	}
	
	//修改图书
	public String edit(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Map map = req.getParameterMap();
		Book book = CommonUtils.toBean(map, Book.class);
		Category category = CommonUtils.toBean(map, Category.class);
		book.setCategory(category);
		bookService.edit(book);
		req.setAttribute("code", "success");
		req.setAttribute("msg", "修改成功");
		return "f:/frontpages/msg1.jsp";
	}
	
	//加载图书
	public String load(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String bid = req.getParameter("bid");
		Book book = bookService.load(bid);
		req.setAttribute("book", book);
		req.setAttribute("parents", categoryService.findParents());
		String pid = book.getCategory().getParent().getCid();
		req.setAttribute("children", categoryService.findChildren(pid));
		return "f:/adminjsps/admin/book/desc.jsp";
	}
	
	//添加图书:第一步
	public String addPre(HttpServletRequest req, HttpServletResponse resp)
	
	public String addChild(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Category child = CommonUtils.toBean(req.getParameterMap(), Category.class);
		child.setCid(CommonUtils.uuid());//设置cid
		String pid = req.getParameter("pid");
		Category parent = new Category();
		parent.setCid(pid);
		child.setParent(parent);
		categoryService.add(child);
		return findAll(req, resp);
	}
	
	//添加第二分类准备工作
	public String addChildPre(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String pid = req.getParameter("pid");//当前点击的父分类id
		List<Category> parents = categoryService.findParents();
		req.setAttribute("pid", pid);
		req.setAttribute("parents", parents);
		
		return "f:/adminjsps/admin/category/add2.jsp";
	}
	
	//修改一级分类准备工作
	public String editParentPre(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String cid = req.getParameter("cid");
		Category parent = categoryService.load(cid);
		req.setAttribute("parent", parent);
		return "f:/adminjsps/admin/category/edit.jsp";
	}

	public String editParent(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Category parent = CommonUtils.toBean(req.getParameterMap(), Category.class);
		categoryService.edit(parent);
		return findAll(req, resp);
	}
	
	//修改二级分类:第一步
	public String editChildPre(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String cid = req.getParameter("cid");
	
	// 多条件组合查询
	public String findByCombination(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		Book criteria = CommonUtils.toBean(req.getParameterMap(), Book.class);
		PageBean<Book> pb = bookService.findByCombination(criteria, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/frontpages/book/list.jsp";
	}

	//图书排行
	public String findBookRanding(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Book> bookList = bookService.bookRankingList();
		req.setAttribute("bookList", bookList);
		return "f:/frontpages/bookRanking.jsp";
	}

	// 查询导航的书籍
	public String findBannerBook(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Book> bookList = bookService.bookRankingList();
		req.setAttribute("bookList", bookList);
		return "f:/frontpages/body.jsp";
	}
}

		return "f:/frontpages/cart/list.jsp";
	}
}

public class AdminOrderServlet extends MyServlet {

	private OrderService orderService = new OrderService();
	
	// 查看所有订单
	public String findAll(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		PageBean<Order> pb = orderService.findAll(pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/adminjsps/admin/order/list.jsp";
	}
	
	// 按状态查询
	public String findByStatus(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		int status = Integer.parseInt(req.getParameter("status"));
		PageBean<Order> pb = orderService.findByStatus(status, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/adminjsps/admin/order/list.jsp";
	}
	
	// 查看订单详细信息
	public String load(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String oid = req.getParameter("oid");
		Order order = orderService.load(oid);
		req.setAttribute("order", order);
		String btn = req.getParameter("btn");//btn说明了用户点击哪个超链接来访问本方法的
		req.setAttribute("btn", btn);
        } else {
            try {
                return new String(value.getBytes("ISO-8859-1"), this.charset);
            } catch (UnsupportedEncodingException var4) {
                throw new RuntimeException(var4);
            }
        }
    }

    public Map getParameterMap() {
        Map<String, String[]> map = this.request.getParameterMap();
        if (map == null) {
            return map;
        } else {
            Iterator var3 = map.keySet().iterator();

            while(var3.hasNext()) {
                String key = (String)var3.next();
                String[] values = (String[])map.get(key);

                for(int i = 0; i < values.length; ++i) {
                    try {
                        values[i] = new String(values[i].getBytes("ISO-8859-1"), this.charset);
                    } catch (UnsupportedEncodingException var7) {
                        throw new RuntimeException(var7);
                    }
                }
            }

            return map;
        }
    }

    public String[] getParameterValues(String name) {
        String[] values = super.getParameterValues(name);

        for(int i = 0; i < values.length; ++i) {
            try {
                values[i] = new String(values[i].getBytes("ISO-8859-1"), this.charset);
            } catch (UnsupportedEncodingException var5) {
                throw new RuntimeException(var5);
            }
        }


	//支付
	public String payment(HttpServletRequest req, HttpServletResponse resp) throws SQLException {
		String oid = req.getParameter("oid");
		int status = orderService.findStatus(oid);
		if(status != 1) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "订单转态不对,不能支付!");
			return "f:/frontpages/msg.jsp";
		}
		String password=req.getParameter("password");
		User user=(User)req.getSession().getAttribute("sessionUser");
		String ps=user.getLoginpass();
		if(password.equals(ps)) {
			orderService.updateStatus(oid, 2);
			req.setAttribute("code", "success");
			req.setAttribute("msg", "支付成功");
			return "f:/frontpages/msg1.jsp";
		}else{
			req.setAttribute("code", "error");
			req.setAttribute("msg", "支付错误,密码错误");
			return "f:/frontpages/msg1.jsp";
		}
	}
	
	//取消订单
	public String cancel(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String oid = req.getParameter("oid");
		int status = orderService.findStatus(oid);
		//如果状态码不是1未付款,则转发到错误页面
		if(status != 1) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "状态不对,不能取消!");
			return "f:/jsps/msg1.jsp";
		}
		orderService.updateStatus(oid, 5);//设置状态为取消!
		req.setAttribute("code", "success");
		req.setAttribute("msg", "您的订单已取消,您不后悔吗!");
		return "f:/frontpages/msg1.jsp";
	}
	
	// 确认收货
	public String confirm(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
    }
}

public class LoginFilter implements Filter {
	public void destroy() {

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		Object user = req.getSession().getAttribute("sessionUser");
		if(user == null) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "您还没有登录,不能访问本资源");
			req.getRequestDispatcher("/frontpages/msg.jsp").forward(req, response);//请求转发
		} else {
			chain.doFilter(request, response);//放行
		}
	}

	public void init(FilterConfig fConfig) throws ServletException {

	}
}

		if(password.equals(ps)) {
			orderService.updateStatus(oid, 2);
			req.setAttribute("code", "success");
			req.setAttribute("msg", "支付成功");
			return "f:/frontpages/msg1.jsp";
		}else{
			req.setAttribute("code", "error");
			req.setAttribute("msg", "支付错误,密码错误");
			return "f:/frontpages/msg1.jsp";
		}
	}
	
	//取消订单
	public String cancel(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String oid = req.getParameter("oid");
		int status = orderService.findStatus(oid);
		//如果状态码不是1未付款,则转发到错误页面
		if(status != 1) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "状态不对,不能取消!");
			return "f:/jsps/msg1.jsp";
		}
		orderService.updateStatus(oid, 5);//设置状态为取消!
		req.setAttribute("code", "success");
		req.setAttribute("msg", "您的订单已取消,您不后悔吗!");
		return "f:/frontpages/msg1.jsp";
	}
	
	// 确认收货
	public String confirm(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String oid = req.getParameter("oid");
		int status = orderService.findStatus(oid);
		if(status != 3) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "状态不对,不能确认收货!");
			return "f:/frontpages/msg1.jsp";
		}
		orderService.updateStatus(oid, 4);//设置状态为交易成功
                    request.getRequestDispatcher(result).forward(request, response);
                } else {//如果存在冒号
                    String start = result.substring(0, index);//分割出前缀
                    String path = result.substring(index + 1);//分割出路径
                    if(start.equals("f")) {//前缀为f表示转发
                        request.getRequestDispatcher(path).forward(request, response);
                    } else if(start.equals("r")) {//前缀为r表示重定向
                        response.sendRedirect(request.getContextPath() + path);
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public int getPc(HttpServletRequest req) {
        int pc = 1;
        String param = req.getParameter("pc");
        if(param != null && !param.trim().isEmpty()) {
            try {
                pc = Integer.parseInt(param);
            } catch(RuntimeException e) {}
        }
        return pc;
    }

    public String getUrl(HttpServletRequest req) {
        String url = req.getRequestURI() + "?" + req.getQueryString();
        int index = url.lastIndexOf("&pc=");
        if(index != -1) {
            url = url.substring(0, index);
        }
        return url;
    }
}

//再doilter中可能用到
public class RightRequest extends HttpServletRequestWrapper {
	
	//Email是否注册校验
	public String ajaxValidateEmail(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String email = req.getParameter("email");
		boolean b = userService.ajaxValidateEmail(email);
		resp.getWriter().print(b);
		return null;
	}
	
	//图片验证码是否正确校验
	public String ajaxValidateVerifyCode(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String verifyCode = req.getParameter("verifyCode");
		String vcode = (String) req.getSession().getAttribute("vCode");
		boolean b = verifyCode.equalsIgnoreCase(vcode);
		resp.getWriter().print(b);
		return null;
	}

	//注册功能
	public String regist(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);//拿到表单数据
		//校验之, 如果校验失败,保存错误信息,返回到regist.jsp显示
		Map<String,String> errors = validateRegist(formUser, req.getSession());
		if(errors.size() > 0) {
			req.setAttribute("form", formUser);
			req.setAttribute("errors", errors);
			return "f:/frontpages/user/register.jsp";
		}
		//使用service完成业务
		userService.regist(formUser);
		//保存成功信息,转发到msg.jsp显示!
		req.setAttribute("code", "success");
		req.setAttribute("msg", "注册成功!");
		return "f:/frontpages/msg.jsp";
	}
	
		req.setAttribute("code", "success");
		req.setAttribute("msg", "您的订单已取消");
		return "f:/frontpages/msg1.jsp";
	}
	
	//发货功能
	public String deliver(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String oid = req.getParameter("oid");
		int status = orderService.findStatus(oid);
		if(status != 2) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "状态不对,不能发货!");
			return "f:/frontpages/msg1.jsp";
		}
		orderService.updateStatus(oid, 3);//设置状态为取消!
		req.setAttribute("code", "success");
		req.setAttribute("msg", "您的订单已发货,请查看物流,马上确认吧!");
		return "f:/frontpages/msg1.jsp";
	}
}

@SuppressWarnings("serial")
public class MyServlet extends HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");//处理响应编码
        //1. 获取method参数,它是用户想调用的方法
        String methodName = request.getParameter("method");
        Method method = null;
        //2. 通过方法名称获取Method对象
	
	// 多条件组合查询
	public String findByCombination(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int pc = getPc(req);
		String url = getUrl(req);
		Book criteria = CommonUtils.toBean(req.getParameterMap(), Book.class);
		PageBean<Book> pb = bookService.findByCombination(criteria, pc);
		pb.setUrl(url);
		req.setAttribute("pb", pb);
		return "f:/frontpages/book/list.jsp";
	}

	//图书排行
	public String findBookRanding(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Book> bookList = bookService.bookRankingList();
		req.setAttribute("bookList", bookList);
		return "f:/frontpages/bookRanking.jsp";
	}

	// 查询导航的书籍
	public String findBannerBook(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		List<Book> bookList = bookService.bookRankingList();
		req.setAttribute("bookList", bookList);
		return "f:/frontpages/body.jsp";
	}
}

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 9
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值