7.编写JSP程序,使用<c:choose>、 <c:when> 和<c:otherwise>标签根据当前是星期几而显示不同的提示信息。
时间: 2024-04-30 18:23:06 浏览: 141
一个用汇编实现输入一个时间显示是星期几的程序
3星 · 编辑精心推荐
```jsp
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String[] daysOfWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
int dayOfWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1;
%>
<c:choose>
<c:when test="${dayOfWeek == 0}">
<p>Today is ${daysOfWeek[0]}. It's a good day to relax.</p>
</c:when>
<c:when test="${dayOfWeek == 1}">
<p>Today is ${daysOfWeek[1]}. It's a good day to start working.</p>
</c:when>
<c:when test="${dayOfWeek == 2}">
<p>Today is ${daysOfWeek[2]}. It's a good day to learn something new.</p>
</c:when>
<c:when test="${dayOfWeek == 3}">
<p>Today is ${daysOfWeek[3]}. It's a good day to meet friends.</p>
</c:when>
<c:when test="${dayOfWeek == 4}">
<p>Today is ${daysOfWeek[4]}. It's a good day to plan for the weekend.</p>
</c:when>
<c:when test="${dayOfWeek == 5}">
<p>Today is ${daysOfWeek[5]}. It's a good day to finish your work.</p>
</c:when>
<c:when test="${dayOfWeek == 6}">
<p>Today is ${daysOfWeek[6]}. It's a good day to relax and have fun.</p>
</c:when>
<c:otherwise>
<p>Oops, something went wrong!</p>
</c:otherwise>
</c:choose>
```
阅读全文