编写jsp程序使用<c:choose>,<c:when>和<otherwise>表签根据当前是星期几而显示不同的信息
时间: 2024-01-29 22:54:19 浏览: 93
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
//获取当前星期几
int week = Calendar.getInstance().get(Calendar.DAY_OF_WEEK);
%>
<c:choose>
<c:when test="${week==1}">
<p>今天是星期日,祝您有一个愉快的周末!</p>
</c:when>
<c:when test="${week==2}">
<p>今天是星期一,加油!</p>
</c:when>
<c:when test="${week==3}">
<p>今天是星期二,加油!</p>
</c:when>
<c:when test="${week==4}">
<p>今天是星期三,加油!</p>
</c:when>
<c:when test="${week==5}">
<p>今天是星期四,加油!</p>
</c:when>
<c:when test="${week==6}">
<p>今天是星期五,周末就快到了!</p>
</c:when>
<otherwise>
<p>今天是星期六,祝您有一个愉快的周末!</p>
</otherwise>
</c:choose>
相关问题
编写jsp程序,使用<c:choose>、<c:when>、<c:otherwise>标签根据当前是星期几显示提示信息
<%@ 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>
编写jsp程序,使用<c:choose>、<c:when>、<c:otherwise>标签根据当前是星期几显示提示中文信息
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
//获取当前的星期几
java.util.Calendar cal = java.util.Calendar.getInstance();
int dayOfWeek = cal.get(java.util.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>
阅读全文