jsp if else语句使用方法
jsp if else语句使用方法
发布时间:2015-06-05 来源:查字典编辑
摘要:ifelse在大部份编程语言中都是这样使用的,我们今天来简单的介绍一下关于jsp教程中的ifelse与多重条件判断。UsingtheifSt...

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 / Saturday.");
else if (day == "Sunday")
out.println("It's Sunday.");
%>
</BODY>
</HTML>

以上是三联网为您介绍的jsp if else语句使用方法,希望对您有所帮助。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新JSP教程学习
热门JSP教程学习
编程开发子分类