编写jsp程序,使用<c:choose>.<c:when>和<c:otherwise>标签根据当前是星期几而显示不同的提示信息
时间: 2024-05-24 21:10:47 浏览: 167
一个用汇编实现输入一个时间显示是星期几的程序
3星 · 编辑精心推荐
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
//获取当前星期几
Calendar cal = Calendar.getInstance();
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
%>
<c:choose>
<c:when test="${dayOfWeek==1}">
<p>今天是星期日,放松一下吧!</p>
</c:when>
<c:when test="${dayOfWeek==2}">
<p>今天是星期一,加油工作!</p>
</c:when>
<c:when test="${dayOfWeek==3}">
<p>今天是星期二,继续加油!</p>
</c:when>
<c:when test="${dayOfWeek==4}">
<p>今天是星期三,半周过去了!</p>
</c:when>
<c:when test="${dayOfWeek==5}">
<p>今天是星期四,再努力一下!</p>
</c:when>
<c:when test="${dayOfWeek==6}">
<p>今天是星期五,快乐周末马上到来!</p>
</c:when>
<c:when test="${dayOfWeek==7}">
<p>今天是星期六,好好休息一下!</p>
</c:when>
<c:otherwise>
<p>未知星期几,祝你愉快!</p>
</c:otherwise>
</c:choose>
阅读全文