使用shiro框架时,验证登录成功,跳转到successUrl时出现 getOutputStream() has already been called for this response

刘朕 发布于 2016/07/16 22:13
阅读 930
收藏 0

    大家好,最近再写个项目,使用shiro框架作为权限管理,因为系统有后台管理功能和前台用户的登录,在shiro验证成功后,跳转到successURl时总是出现Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response,请问下,这个问题如何解决。

跳转到succesUrl的代码为

public class BaseFormAuthenticationFilter extends FormAuthenticationFilter {


@Override
    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject,
            ServletRequest request, ServletResponse response) throws Exception {
//issueSuccessRedirect(request, response);
//we handled the success redirect directly, prevent the chain from continuing:
HttpServletRequest httpServletRequest = (HttpServletRequest)request;
HttpServletResponse httpServletResponse = (HttpServletResponse)response;
if (!"XMLHttpRequest".equalsIgnoreCase(httpServletRequest.getHeader("X-Requested-With")) 
|| request.getParameter("ajax") == null) {// 不是ajax请求
//WebUtils.issueRedirect(httpServletRequest, httpServletResponse, httpServletRequest.getContextPath() + this.getSuccessUrl());
httpServletResponse.sendRedirect(httpServletRequest.getContextPath() + this.getSuccessUrl());
saveRequest(httpServletRequest);
} else {
httpServletRequest.getRequestDispatcher("/login/timeout/success").forward(httpServletRequest, httpServletResponse);
}
return false;
}
}

加载中
0
东胜神洲
东胜神洲

如果没有特定的需要,最好还是遵循 Shiro 的框架配置,在配置文件中配置 Success URL,让 shiro 来跳转。。

如果是特定的需要的话,你可以看看 FormAuthenticationFilter 的源代码实现,当需要用到非常底层的操作时,估计继承 FormAuthenticationFilter 还是高了一点。。又或者,你可以不用 response 这样的底层返回,而是用用 FormAuthenticationFilter (或父类)提供的返回方法来返回。。

因为,OutputStream 之类的流,通常在一个地方用过之后,就不能再次使用。。所以要么自己接管来用,要么就交给 shiro 来用。。




刘朕
我看了下页面的jsessionId,为什么点击两次登陆后,jsessionId会不一致呢
返回顶部
顶部