How to use the JSP if Else statement

Source: Internet
Author: User

If else is used in most programming languages, let's briefly talk about if else and multiple condition judgments in the JSP tutorial today.

<HTML>
<HEAD>
<title>using the If statement</title>
</HEAD>

<BODY>
<%
int value = 10;

if (Value > 0)
OUT.PRINTLN ("absolute value of" + value + "=" + value);
%>
</BODY>
</HTML>
Simple contrast

<HTML>
<HEAD>
<title>using Compound statements</title>
</HEAD>

<BODY>
<%
int value = 10;

if (value > 0) {
Out.println ("The number was positive.");
OUT.PRINTLN ("absolute value of" + value + "=" + value);
}
%>
</BODY>
</HTML>

If Else

<HTML>
<HEAD>
<title>nested if statements</title>
</HEAD>

<BODY>
<%
Double value = 2;

if (value!= 0) {
if (Value > 0)
OUT.PRINTLN ("The result =" + (1/value));
Else
Out.println ("Sorry, we need a positive number.");
}
%>
</BODY>
</HTML>
Multiple conditions if Else

<HTML>
<HEAD>
<title>using an if-else ladder</title>
</HEAD>

  <body>
        < %
        String day = "Friday";

        if (day = = "Monday")
             out.println ("It ' s Monday.");
        Else if (day = = "Tuesday")
             out.println ("It ' s Tuesday.");
        Else if (day = = "Wednesday")
             out.println ("It ' s Wednesday.");
        Else if (day = = "Thurssday")
             out.println ("It ' s Thursday.");
        Else if (day = = "Friday")
             out.println ("It ' s Friday.");
        Else if (day = = "Saturday")
      & Nbsp;     out.println ("It ' S http://www.3lian.com/saturday.");
        Else if (day = = "Sunday")
             out.println ("It ' s Sunday.");
   %>
  </BODY>

Above is the three networking for you to introduce the JSP if Else statement use method, I hope to help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.