<c:catch> and <fmt:parseNumber> not working

D

Derek Mahar

Why does Tomcat 5.0.9 throw exception java.lang.NumberFormatException
when it executes the following JSTL code with amount equal to "asdf"?
Shouldn't <c:catch> catch the exception, assign the error code to
amountError, and allow Tomcat to continue processing the page?

Configuration:
JSTL 1.1 in Sun Java Web Services Developer Pack 1.2
Tomcat 5.0.9

<%-- Validate amount. --%>
<c:catch var="amountError">
<%-- Parse the amount entry to see if it is a valid integer and to
remove commas and decimals. --%>
<fmt:parseNumber
var="parseAmount"
value="${amount}"/>

<%-- Check that order amount is not zero. --%>
<c:if test="${amount == 0}" var="isZeroAmount"/>
</c:catch>
<c:if test="${not empty amountError}" var="isBadAmount"/>

HTTP Status 500 -

------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception

javax.servlet.ServletException: In <formatNumber>, value attribute can
not be parsed into java.lang.Number: "asdf"
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:679)
org.apache.jsp.Trader.ActionOrderCreate_jsp._jspService(ActionOrderCreate_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause

java.lang.NumberFormatException: For input string: "asdf"
java.lang.NumberFormatException.forInputString(Unknown Source)
java.lang.Long.parseLong(Unknown Source)
java.lang.Long.valueOf(Unknown Source)
org.apache.taglibs.standard.tag.common.fmt.FormatNumberSupport.doEndTag(FormatNumberSupport.java:190)
org.apache.jsp.tag.web.formatAmount_tag._jspx_meth_fmt_formatNumber_0(formatAmount_tag.java:101)
org.apache.jsp.tag.web.formatAmount_tag.doTag(formatAmount_tag.java:54)
org.apache.jsp.tag.web.orderEnter_tag._jspx_meth_bond_formatAmount_0(orderEnter_tag.java:1281)
org.apache.jsp.tag.web.orderEnter_tag.doTag(orderEnter_tag.java:287)
org.apache.jsp.Trader.ActionOrderCreate_jsp._jspx_meth_bond_orderEnter_0(ActionOrderCreate_jsp.java:120)
org.apache.jsp.Trader.ActionOrderCreate_jsp._jspService(ActionOrderCreate_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:293)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

note The full stack trace of the root cause is available in the Tomcat
logs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top