日期:2014-05-18  浏览次数:20799 次

一个基础的问题,大家看看
如果用下面的代码:
request.setAttribute( "error ",   "密码错! ");
request.getRequestDispatcher( "hello.jsp ").forward(request,   response);
那么hello.jsp里是可一用getAttribute( "error ")得到的

但是为什么改用
request.setAttribute( "error ",   "密码错! ");
response.sendRedirect( "hello.jsp ");下面的代码以后确不能用getAttribute( "error ")得到error了呢?

request.getRequestDispatcher( "hello.jsp ").forward(request,   response);
response.sendRedirect( "hello.jsp ");这两句话有什么区别


------解决方案--------------------
response.sendRedirect()好像是服务器跳转吧,相当于重新发了一次请求,你把他保存在SESSION属性中,应该就没有问题了吧,,(这个问题有点记不清,不过肯定是服务器跳转和客户端跳转之间的区别,你再查一下资料吧,)
------解决方案--------------------
request.getRequestDispatcher( "hello.jsp ").forward(request, response);是后台的跳转
response.sendRedirect( "hello.jsp ");是前台跳转,也就是重定向,是又向服务器发了一次请求
相当于直接访问hello.jsp,request里的东西当然没有了

应该是这个问题吧!! 我也是个新手。

还望大家批评,指正