JSF 2 -- 永久重定向 (301)

标签 jsf redirect jsf-2 http-status-code-301

我正在尝试从 JSF 中实现 301 重定向,但是当我对其进行调试时,我总是看到正在执行 302。有人能告诉我如何改变下面的方法来完成 301 吗?

/**
 * Redirect to specified destination url
 *
 * @param destination
 */
public static void permanentRedirect(String destination) {
    final ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();

    try {
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
        response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

        if (!response.isCommitted()) {
            externalContext.redirect(destination);
        }
    } catch (IOException e) {
        LOGGER.debug("Could not redirect to " + destination);
    }
} 

最佳答案

你不应该调用 externalContext.redirect(destination) .它会将状态覆盖为 302。您应该手动 set the Location headercomplete the response .

externalContext.setResponseStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
externalContext.setResponseHeader("Location", destination);
facesContext.responseComplete();

关于JSF 2 -- 永久重定向 (301),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10744949/

相关文章:

ajax - 如何在JSF上延迟Primefaces AjaxStatus?

java - 是否可以加密部分 faces-config 文件?

immediate=true 的 JSF 生命周期

ajax - Uncaught SyntaxError : Unexpected token < in jsf.js.faces?ln=javax.faces

html - 添加 URL 重定向到按钮组按钮

c - 将输出从 stdout 重定向到字符串?

Django Apache 重定向问题

java - JSF p :commandLink and p:ajax have different behavior in update

jsf-2 - a4j :commandButton passing values in callback

java - 在 javascript 中使用 richfaces 迭代列表中的项目