我的 JSP 页面中有一个接受整数值的复选框:
<form:checkbox path="somePath" value="2" /> Dangerous Checkbox <br />
如果用户将输入的值更改为String
值,例如:
<form:checkbox path="somePath" value="blah" /> Dangerous Checkbox <br />
页面会抛出一个NumberFormatException
。我怎样才能在我的控制器中捕捉到这个并显示有意义的消息?
你可以使用 JSTLc:catch tag:
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)