【发布时间】:2021-05-18 07:51:07
【问题描述】:
我遇到了来自我们的一位用户的问题。不知何故,用户只需单击一下即可进行多次重定向。这样做会多次调用重定向方法,这会导致 IllegalStateException。我尝试首先检查响应是否已提交,如果未提交响应,则仅调用重定向方法。它有效。只有一个重定向请求而不是全部被发送到浏览器。但我想知道是否可以发送多个重定向语句。提交旧响应后是否可以使用新响应创建新请求?
这是提交重定向的工作检查:
public static final boolean redirect(String targetPath) {
try {
if(!isCommitted()) {
exContext().redirect(checkAppendContextPath(targetPath));
return true;
}else{
return false;
}
} catch (IOException e) {
if (LOG.isErrorEnabled()) {
LOG.error(String.format(ERROR_REDIRECT, context().getViewRoot().getViewId(), targetPath));
}
return false;
}
}
private static final boolean isCommitted(){
if(exContext().getResponse() instanceof HttpServletResponse){
if(((HttpServletResponse) exContext().getResponse()).isCommitted()){
return true;
}else{
return false;
}
}else{
return false;
}
}
【问题讨论】: