Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using jstl formatNumber with rs.getString

 
Carl Zeigler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am trying to use the formatNumber function to display a string value returned from a database via rs.getString(). I have been testing the formatNumber function and see how it works but I cannot figure out how to pass the string returned from the database into the value parameter of the formatNumber fucntion. Is there any way I can do this?



Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mixing scriptlets and JSTL/EL in a JSP page is recipe for complete and utter disaster.

You should do two things in order of importance:

  • Never ever, and did I mention ever, send a resultset to a JSP. Rather, copy the data from the resultset into a Java collection immediately after fetching it and release the resultset. This collection (List, array, whatever) is what gets sent to the JSP.
  • Use no scriptlets or other Java code in a JSP. That's a practice that has been discredited for almot 10 years now.
  •  
    Miku Ranjan
    Ranch Hand
    Posts: 98
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    As it is described in the last post you should use jstl/EL and for your scenario you can use a pattern attribute to describe the number format in the jstl tag, formatNumber.
     
    Stefan Evans
    Bartender
    Posts: 1784
    10
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It should probably also be pointed out that the "formatNumber" tag takes a number (ie Integer, Double etc) and turns it into a String.
    The value you are passing in is already a String.

    If what you are getting from the database is a number, I would recommend using the rs.getInt() or rs.getDouble() methods rather than rs.getString().

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic