• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JasperException from non-numeric parameter value

 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I call my JSP with a non-numeric parameter value, I get a Jasper-specific exception. Should I be somehow catching this exception, and if so, how? Doing so would make my JSP Tomcat-specific and thus non-portable, which seems like a very bad thing to do.
My JSP:

My bean:

The error page:

This happens if I call the JSP with an invalid parameter value, for instance
http://localhost:8080/budget/budget.jsp?expense=44a
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want to have happen in these circumstances?
Since request params come in as strings and nothing guarantees that they'll be valid, I'd change the bean mutators to accept a String as the value parameter, convert the string to numeric within the mutator, and deal with any parse exceptions (via any of: supply a default value, throw a meaningful exception, trigger a redirect to an error page... whatever makes the most sense for your app).
hth,
bear
[ July 02, 2003: Message edited by: Bear Bibeault ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess my question is:
Why am I getting a Jasper-specific exception instead of a standard-defined one? This situation must be quite common.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic