If you want to choose to execute one of several blocks of code, you can use the switch statement:
Grammar:
Switch (n)
{
Case 1:
Execute code block 1
Break
Case 2:
Execute code block 2
Break
Default
If n is not 1 or 2, then this code is executed
}
How it works: The (n) behind the switch can be an expression, or it can (and usually) be a variable. The values in the expression are then compared to the numbers in the case, and if they match one, the subsequent code is executed. The function of a break is to prevent the code from automatically executing to the next line.
<HTML>
<HEAD>
<title>using the Switch statement</title>
</HEAD>
<BODY>
<%
int day = 3;
switch (day) {
Case 0:
out.println ("It's Sunday.");
break;
Case 1:
out.println ("It's Monday.");
break;
Case 2:
out.println ("It's Tuesday.");
break;
Case 3:
out.println ("It's Wednesday.");
break;
Case 4:
out.println ("It's Thursday.");
break;
Case 5:
out.println ("It's Friday.");
Break
Default:
out.println ("It must be Saturday.");
}
%>
</BODY>
</HTML>
Another situation
<HTML>
<HEAD>
<title>testing for multiple conditions</title>
</HEAD>
<BODY>
<%
int temperature = 64;
switch (temperature) {
Case 60:
Case 61:
Case 62:
out.println ("Sorry, Too cold!");
break;
Case 63:
Case 64:
Case 65:
out.println ("pretty cool.");
Break
Case 66:
Case 67:
Case 68:
Case 69:
out.println ("nice!");
break;
Case 70:
Case 71:
Case 72:
Case 73:
Case 74:
Case 75:
out.println ("fairly warm.");
break;
Default:
out.println ("Too hot!");
}
%>
</BODY>
</HTML>
The above is the three networking for you to introduce the JSP switch statement usage, I hope to help you.