sendRedirect是页面重定向,地址栏信息改变,可以跳转到任意网页。
//获得所有的商品的类别数据 AdminProductService service = new AdminProductService(); List<Category> categoryList = null; try { categoryList = service.findAllCategory(); } catch (SQLException e) { e.printStackTrace(); } request.setAttribute("categoryList", categoryList); request.getRequestDispatcher("/admin/product/add.jsp").forward(request, response);
AdminProductService service = new AdminProductService(); try { service.addProduct(product); } catch (SQLException e) { e.printStackTrace(); } //跳转到列表页面 response.sendRedirect(request.getContextPath()+"/adminProductList");