熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

jsp if else語句使用方法

2013-11-15 12:12:21  來源: JSP教程 

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

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

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

  if(value > )
            outprintln("Absolute value of " + value + " = " + value);
    %>
  </BODY>
</HTML>
簡單對比

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

  <BODY>
    <H>Using Compound Statements</H>
    <%
        int value = ;

  if(value > ) {
            outprintln("The number was positive");               
            outprintln("Absolute value of " + value + " = " + value);
        }
    %>
  </BODY>
</HTML>

  if else

  <HTML>
  <HEAD>
    <TITLE>Nested if Statements</TITLE>
  </HEAD>

  <BODY>
    <H>Nested if Statements</H>
    <%
        double value = ;

  if (value != ) {
            if (value > )
               outprintln("The result = " + ( / value));
            else
               outprintln("Sorry we need a positive number");
        }
    %>
  </BODY>
</HTML>
多個條件if else

  <HTML>
  <HEAD>
    <TITLE>Using an ifelse Ladder</TITLE>
  </HEAD>

  <BODY>
    <H>Using an ifelse Ladder</H>
    <%
        String day = "Friday";

  if(day == "Monday")
            outprintln("Its Monday");
        else if (day == "Tuesday")
            outprintln("Its Tuesday");
        else if (day == "Wednesday")
            outprintln("Its Wednesday");
        else if (day == "Thurssday")
            outprintln("Its Thursday");
        else if (day == "Friday")
            outprintln("Its Friday");
        else if (day == "Saturday")
            outprintln("It
        else if (day == "Sunday")
            outprintln("Its Sunday");
    %>
  </BODY>
</HTML>

  以上是網為您介紹的jsp if else語句使用方法希望對您有所幫助


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20495.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.