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");