2013-11-04 35 views
0

enter image description here共享驗證,如何改變NumberFormatException的

的消息,我想改變NumberFormatException異常的消息。請告訴我該怎麼做。 謝謝。

+0

可否請你發佈的代碼示例 - 你如何驗證你的電話號碼? –

+0

這工作對我來說:http://stackoverflow.com/a/15143839/ –

+0

我想這應該是作爲重複關閉https://stackoverflow.com/questions/15104012/how-to-customize-default-message- for-bigdecimal ...? –

回答

0

一種方式來做到這一點,捕捉控制器中的異常,並在請求中設置適當的錯誤消息(在這種情況下您的自定義消息)。請檢查請求中是否存在錯誤消息,並將其顯示在int視圖中。

控制器:

try{ 
    //your logic goes here 
    }catch(NumberFormatException ex){ 
    request.setAttribute("ERROR_MSG" , " YOUR CUSTOMER MESSAGE GOES HERE"); 
} 

JSP:

檢查,如果錯誤味精存在於請求對象,此消息添加到文本提示。

另外,如果用戶正在使用Struts,使用的ActionErrors的