我不希望使用每次:有沒有簡單的方法來處理JSP文件中的404錯誤?
if(!new File(file).exists()){
//createFile /doc/a.txt ...
}
request.getRequestDispatcher("/doc/a.txt").forward(request, response);
我想知道我怎樣才能實現下面的代碼:
try{
request.getRequestDispatcher("/doc/a.txt").forward(request, response);
}catch(404 error){
//createFile /doc/a.txt ...
}
我怎麼能交給404錯誤只是在這個網頁?
非常感謝您的任何建議。
感謝的答案,但我只需要發放404錯誤只是在此頁面中,不是全部 – Koerr
是的。這是一個完美的解決方案。無需在try catch中處理Exception。只要提到應用程序遇到HTTP 404錯誤時顯示的錯誤頁面名稱即可。 –
你是對的@ Reimeus,我覺得這有點複雜,我正在尋找一個更簡單的方法,如果可能 – Koerr