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

The JSP Files (part 3): Black Light And White Rabbits

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.

  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


Last time out, you learned a little bit about the various conditional statements and operators available in JSP. This week, we'll expand on those basics by teaching you a little bit about the different types of loops available in JSP, discuss a few more String object methods, and take a quick tour of the new Response object.

First up, loops.

As you may already know, a "loop" is a programming construct that allows you to execute a set of statements over and over again, until a pre-defined condition is met.

The most basic loop available in JSP is the "while" loop, and it looks like this:

while (condition) { do this! }
Or, to make the concept clearer,

while (temperature is below freezing) { wear a sweater }
The "condition" here is a standard conditional expression, which evaluates to either true or false. So, were we to write the above example in JSP, it would look like this:

while (temp <= 0) { sweater = true; }
Here's an example:

<html> <head> </head> <body> <%! int countdown=30; %> <% while (countdown > 0) { out.println(countdown + " "); countdown--; } out.println("<b>Kaboom!</b>"); %> </body> </html>
Here, the variable "countdown" is initialized to 30, and a "while" loop is used to decrement the value of the variable until it reaches 0. Once the value of the variable is 0, the conditional expression evaluates as false, and the lines following the loop are executed.

Here's the output:

30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Kaboom!

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- 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: