Jsf FacesContext.getCurrentInstance().getExternalContext().redirect不会立即重定向

Jsf FacesContext.getCurrentInstance().getExternalContext().redirect不会立即重定向,jsf,redirect,Jsf,Redirect,Id作为Url参数传入。我试图确保id是一个数字。如果没有,则重定向到主页 if(facilityId != null){ try{ Long.parseLong(facilityId); }catch(NumberFormatException e){ try { FacesContext.getCurrentInstance().getExternalContext().redirect("DisplayList.jsf

Id
作为Url参数传入。我试图确保
id
是一个数字。如果没有,则重定向到主页

if(facilityId != null){
    try{
        Long.parseLong(facilityId);
    }catch(NumberFormatException e){
        try {
            FacesContext.getCurrentInstance().getExternalContext().redirect("DisplayList.jsf");                    
        } catch (IOException ex) {}
    }
    facility = documentSBean.findFacilityById(Long.parseLong(facilityId));
    ...
}
所以如果我通过一个像这样的身份证

www....?facilityId=3?sdfasfda

我发现
3?sdfasfda
不是一个数字,并转到redirect语句,但它没有正确重定向,它执行下几行,试图将
3?sdfasfda
转换为Long,因此产生
NumberFormatException
。那么,有没有一种方法可以立即强制重定向,或者有没有其他方法可以解决这个问题呢。希望在捕获之后有一个
else
:D:D。上面的代码在我的
@PostConstruct init()
方法中是的,只需从方法返回

FacesContext.getCurrentInstance()
   .getExternalContext().redirect("DisplayList.jsf");
return;

调用
重定向(…)
时,唯一发生的事情是在响应对象中设置了一个特殊的头(
位置
)。但是调用方法的流程将继续,除非在调用redirect之后
从它返回

ai ya。为什么我没想到呢。谢谢:D。你知道为什么重定向会有延迟吗?当你返回时不会有延迟。