六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 36|回复: 0

Redirect or Forward

[复制链接]

升级  58%

41

主题

41

主题

41

主题

秀才

Rank: 2

积分
137
 楼主| 发表于 2013-1-27 06:15:36 | 显示全部楼层 |阅读模式
如果页面/bb/a.jsp
假设我们有一个Filter的配置为:/bb/*,其中有一段代码为
if( need condition)
   request.setAttribute("errormessage","The Error info.");
   response.sendRedirect(ERROR_FOR_SOME_)
/if
在出错的页面不会看到预期的错误提示,
error_page.jsp
  <c:out value="${errormessage}"></c:out>
Of course we cannot see any error info here,because of using the "sendRedirect"!!!
注意:redirect!!!修改为:
  request.getRequestDispatcher(ERROR_FOR_SOME_).forward(request,response);
问题可解决
如果又在/bb/a.jsp页面中使用了:
<jsp:forward page="/some.jsp"/>
Error:Cannot forward after response has been committed
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表