编写jsp程序,使用<c:choose>、<c:when>、<c:otherwise>标签根据当前是星期几显示提示信息
时间: 2024-05-31 17:06:57 浏览: 61
JavaScript获取当前日期是星期几的方法
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
java.util.Date date = new java.util.Date();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("EEEE");
String dayOfWeek = sdf.format(date);
%>
<c:choose>
<c:when test="${dayOfWeek == 'Monday'}">
<p>Today is Monday. Have a great start to the week!</p>
</c:when>
<c:when test="${dayOfWeek == 'Tuesday'}">
<p>Today is Tuesday. Keep pushing through the week!</p>
</c:when>
<c:when test="${dayOfWeek == 'Wednesday'}">
<p>Today is Wednesday. Halfway through the week!</p>
</c:when>
<c:when test="${dayOfWeek == 'Thursday'}">
<p>Today is Thursday. Almost there!</p>
</c:when>
<c:when test="${dayOfWeek == 'Friday'}">
<p>Today is Friday. Weekend is just around the corner!</p>
</c:when>
<c:when test="${dayOfWeek == 'Saturday'}">
<p>Today is Saturday. Enjoy your weekend!</p>
</c:when>
<c:when test="${dayOfWeek == 'Sunday'}">
<p>Today is Sunday. Rest and recharge for the week ahead!</p>
</c:when>
<c:otherwise>
<p>Oops, something went wrong!</p>
</c:otherwise>
</c:choose>
阅读全文