流程控制在程序中会根据不同的条件处理不同的业务,即执行不同的程序代码来产生不同运行结果,使用流程控制可以处理程序中的任何可能发生的事件。在JSTL中包含<c:if>、<c:choose>、<c:when>和<c:otherwise>4种流程控制标签。
score.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>使用流程控制标签划分成绩</title>
</head>
<body>
<c:if test="${empty param.score }" var="result">
<form action="" method="post" name="form1">
成绩: <input name="score" type="text" id="score">
<input type="submit" value="查询">
</form>
</c:if>
<c:if test="${!result}">
<c:choose>
<c:when test="${param.score>=90&¶m.score<=100}">
你的成绩为优秀!
</c:when>
<c:when test="${param.score>=70&¶m.score<=90}">
你的成绩为良好!
</c:when>
<c:when test="${param.score>=60&¶m.score<=70}">
你的成绩为及格!
</c:when>
<c:when test="${param.score>=0&¶m.score<=60}">
对不起,您没有通过考试!
</c:when>
<c:otherwise>
对不起,您输入的成绩无效!
</c:otherwise>
</c:choose>
</c:if>
</body>
</html>