簡體   English   中英

ExternalContext 重定向導致 IllegalStateException

[英]ExternalContext redirect leads to IllegalStateException

我面臨來自我們的一位用戶的問題。 不知何故,用戶只需單擊一下即可進行多次重定向。 這樣做會多次調用重定向方法,這會導致 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;
    }
}

不,不能在服務器端發出請求。 它們必須來自客戶端。

我很難相信單擊會觸發多個請求,除非涉及 JavaScript。 如果涉及 JavaScript,請檢查它是否存在錯誤。 否則,您可以嘗試防止在客戶端多次單擊。 如果您使用 PrimeFaces 並且重定向是從p:commandButton觸發的,您可以嘗試使用PrimeFaces Extensions CommandButtonSingleClickRenderer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM