jsp if else語句使用方法

來源:互聯網
上載者:User

if else在大部份程式設計語言中都是這樣使用的,我們今天來簡單的介紹一下關於jsp教程 中的if else 與多重條件判斷。

<HTML>
  <HEAD>
    <TITLE>Using the if Statement</TITLE>
  </HEAD>

  <BODY>
    <H1>Using the if Statement</H1>
    <%
        int value = 10;

        if(value > 0)
            out.println("Absolute value of " + value + " = " + value);
    %>
  </BODY>
</HTML>

簡單對比

<HTML>
  <HEAD>
    <TITLE>Using Compound Statements</TITLE>
  </HEAD>

  <BODY>
    <H1>Using Compound Statements</H1>
    <%
        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>
    <H1>Nested if Statements</H1>
    <%
        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>

多個條件if else

<HTML>
  <HEAD>
    <TITLE>Using an if-else Ladder</TITLE>
  </HEAD>

  <BODY>
    <H1>Using an if-else Ladder</H1>
    <%
        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")
            out.println("It's www.111cn.net/5230/ Saturday.");
        else if (day == "Sunday")
            out.println("It's Sunday.");
    %>
  </BODY>
</HTML>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.