Home arrow Java & J2EE arrow Page 3 - The JSP Files (part 2): Attack Of The Killer Fortune Cookies

Do It Or Else... - Java

The second part of our introductory JSP tutorial discussesarithmetic, logical and comparison operators, together with simple examplesand illustrations. You'll also learn the basics of JSP's numerousconditional expressions, including the "if", "if-else" and "switch"statements, and find out a little more about the String object.

TABLE OF CONTENTS:
  1. The JSP Files (part 2): Attack Of The Killer Fortune Cookies
  2. Flavour Of The Month
  3. Do It Or Else...
  4. Cookie-Cutter Code
  5. Lunch In Milan
  6. Switching Things Around
By: Vikram Vaswani and Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 4
February 22, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
In addition to the "if" statement, JSP also offers the "if-else" statement, which allows you to execute different blocks of code depending on whether the expression is evaluated as true or false.

The structure of an "if-else" statement looks like this:

if (condition) { do this! } else { do this! }
In this case, if the conditional expression evaluates as false, all statements within the curly braces of the "else" block will be executed. Modifying the example above, we have

<%! // declare temperature variable int temp = 50; %> <% // check temperature and display output if (temp > 30) { out.println("Man, it's hot out there!"); } else { out.println("Well, at least it isn't as hot as it could be!"); } %>
In this case, if the first past of the construct fails (temperature is *not* greater than 30), control is transferred to the second part - the "else" statement - and the code within the "else" block is executed instead. You can test both possibilities by adjusting the value of the "temp" variable, and viewing the resulting output in your browser.

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