您的位置:首页 > 编程语言 > PHP开发

Introduction to modules in Zend Framework 2 -- youtube

2013-11-03 18:05 218 查看
当发生在如下错误的时候,有一个方案可行,

"java.lang.IllegalStateException: Cannot forward after response has been committed “

当你有多个跳转的页面的语句时候,好好检查一下,当 转发 或者 重定向的时候,需要在后加一个retrun 即可。

服务器中不允许多次跳转,否则会下面这个错误。

因为服务器端使用sendRedirect跳转到客户端的时候,不能在使用req.getRequestDispatcher("跳转的页面").forward(req, reqs);

跳转;

所以在跳转之后,return就不会往下执行。

1.protected void login(HttpServletRequest req, HttpServletResponse reqs) throws ServletException, IOException {
2.    // TODO Auto-generated method stub
3.    if(req.getUserPrincipal()!=null){
4.        String userID = req.getRemoteUser();
5.        boolean bol = req.isUserInRole(USER_ROLE_ADMIN);
6.        UserModel userModel =connectionDao.getUserModelByUserID(userID);
7.        if(bol){
8.            req.getSession().setAttribute("user",userModel);
9.            reqs.sendRedirect(req.getContextPath()+"/admin/main.jsp");
10.            return;
11.        }else{
12.            reqs.sendRedirect(req.getContextPath()+"/index.jsp");
13.            return;
14.        }
15.    }
16.}

本文转自:/article/4479883.html 感谢原博主!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐