转发与重定向的区别
转发时浏览器中的url地址栏不会发生改变 ,重定向时地址栏会发生改变 转发时浏览器只请求一次服务器,重定向时浏览器请求两次服务器 转发的代码: request.getRequestDispatcher("要转发的jsp页面").forward(request,response); 重定向的代码: response.sendRedirect("jsp的路径"); 注意:重定向无法通过request和response传输数据,但可用以下方法进行数据的传输 this.getServletContext().setAttribute("属性名",属性值); request.getSession().setAttribute("属性名",属性值); 来源: https://www.cnblogs.com/shouyaya/p/12014123.html