随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)
在JSTL中包含<c:if>、<c:choose>、<c:when>、<c:otherwise>4种流程控制标签。
1、<c:if>
<c:if var="result" test="${empty param.username}">
<form name="form1" method="post" action="">
用户名: <input name="username" type="text" id="username" /> <br> <br>
<input type="submit" name="Submit" value="登录" />
</form>
</c:if>
<c:if test="${!result}">
[${param.username}]欢迎访问我公司网站!
</c:if>
2、<c:choose>、<c:when>、<c:otherwise>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>起始页</title>
</head>
<body>
<c:choose>
<c:when test="${empty param.username}">
<form name="form1" method="post" action="">
用户名: <input name="username" type="text" id="username" /> <br> <br>
<input type="submit" value="登录" name="Submit" />
</form>
</c:when>
<c:otherwise>
[${param.username}]欢迎访问我公司网站!
</c:otherwise>
</c:choose>
</body>
</html>