创建jsp程序使用<c:choose>获取今天是星期几
时间: 2024-06-03 12:07:53 浏览: 101
<%@ page language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取今天是星期几</title>
</head>
<body>
<c:choose>
<c:when test="${fn:substring(param.date, 0, 3) == 'Mon'}">
<p>今天是星期一</p>
</c:when>
<c:when test="${fn:substring(param.date, 0, 3) == 'Tue'}">
<p>今天是星期二</p>
</c:when>
<c:when test="${fn:substring(param.date, 0, 3) == 'Wed'}">
<p>今天是星期三</p>
</c:when>
<c:when test="${fn:substring(param.date, 0, 3) == 'Thu'}">
<p>今天是星期四</p>
</c:when>
<c:when test="${fn:substring(param.date, 0, 3) == 'Fri'}">
<p>今天是星期五</p>
</c:when>
<c:when test="${fn:substring(param.date, 0, 3) == 'Sat'}">
<p>今天是星期六</p>
</c:when>
<c:when test="${fn:substring(param.date, 0, 3) == 'Sun'}">
<p>今天是星期日</p>
</c:when>
<c:otherwise>
<p>无法获取今天是星期几</p>
</c:otherwise>
</c:choose>
</body>
</html>
说明:通过<c:choose>和<c:when>标签判断今天是星期几,并输出相应的信息。使用fn:substring()函数截取当前日期的前三个字符,即星期几的缩写。如果无法获取到日期信息,则输出无法获取今天是星期几。
阅读全文