我的JSP页面中有一个接受整数值的复选框:
<form:checkbox path="somePath" value="2" /> Dangerous Checkbox <br />
如果用户将输入值更改为String
值,例如:
<form:checkbox path="somePath" value="blah" /> Dangerous Checkbox <br />
该页面将抛出NumberFormatException
。如何在我的Controller中捕获并显示有意义的消息?
答案 0 :(得分:1)
您可以使用JSTL的c:catch标记:
<c:catch var ="numberFormatException">
<form:checkbox path="somePath" value="blah" /> Dangerous Checkbox <br />
</c:catch>
<c:if test = "${numberFormatException!= null}">
<p>The exception is : ${numberFormatException} <br />
There is an exception: ${numberFormatException.message}</p>
</c:if>