request.getRequestDispatch与response.sendRedirect区别

getRequestDispatcher是服务器内部跳转,地址栏信息不变,只能跳转到web应用内的网页。 
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");
        

 

posted @ 2018-10-10 17:11  Liuyanana  阅读(1086)  评论(0编辑  收藏  举报