6
Id
作爲Url參數傳入。我試圖確保id
是一個數字。如果不是重定向到主網頁FacesContext.getCurrentInstance()。getExternalContext()。重定向不立即重定向
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
一個id我趕上3?sdfasfda
不是一個數字,並獲得了重定向語句,但它不重定向正確的方式,它執行接下來的幾條線,試圖將3?sdfasfda
轉換爲Long,因此收益率爲NumberFormatException
。那麼是否有辦法立即強制重定向,或者有其他方法來解決這個問題。希望在catch
之後有一個else
:D:D。以上代碼是我@PostConstruct init()
方法內
ai ya。爲什麼我沒有想到這一點。謝謝:D。你知道爲什麼重定向有延遲嗎? – 2010-11-04 22:47:55
當你返回時不會有延遲。 – Bozho 2010-11-04 22:49:36