Home arrow Java & J2EE arrow Page 6 - The JSP Files (part 3): Black Light And White Rabbits

You Say Seven, I Say 7 - Java

This week, learn all about the different types of loops supportedby JSP, and also expand your knowledge of the various String objectmethods. Finally, take a quick tour of the JSP Response object inpreparation for learning how JSP handles form data.

TABLE OF CONTENTS:
  1. The JSP Files (part 3): Black Light And White Rabbits
  2. Doing More With Loops
  3. For-gone Conclusion
  4. The Sound Of Breaking Loops
  5. Paying The Piper
  6. You Say Seven, I Say 7
  7. A Positive Response
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 2
March 01, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
And finally, in case you've ever wanted to convert strings to numbers, the following example should tell you everything you need to know.


<% // converting a string to a number

// define variables String someString = "97"; int aRandomNumber = 3;

// at this stage, someString is still treated as a string out.println(someString + " plus " + aRandomNumber + " equals " + (someString+aRandomNumber) + "<p>");

// now convert someString to a number int someNumber = Integer.parseInt(someString);

// at this stage, someString has been converted to a number, stored in someNumber out.println(someNumber + " plus " + aRandomNumber + " equals " + (someNumber+aRandomNumber));

%>


And here's the output.



97 plus 3 equals 973 97 plus 3 equals 100 [output]

If you'd prefer to do things the other way around, the next example bears careful consideration.


<% // define variables int someNumber = 97; int aRandomNumber = 3;

// at this stage, someNumber is still treated as a number out.println(someNumber + " plus " + aRandomNumber + " equals " + (someNumber+aRandomNumber) + "<p>");

// now convert someNumber to a string String someString = Integer.toString(someNumber);

// at this stage, someNumber has been converted to a string, stored in someString out.println(someString + " plus " + aRandomNumber + " equals " + (someString+aRandomNumber));

%>


And here's the output.


97 plus 3 equals 100 97 plus 3 equals 973


The upshot? parseInt() and toString() are your best friends when converting between string and numeric data types in JSP.

 
 
>>> More Java & J2EE Articles          >>> More By Vikram Vaswani and Harish Kamath, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: