jsp日历实现

付费节点推荐


免费节点


节点使用教程


编写一个showCalendar.tag,该Tag文件负责显示日历,编写一个jsp页面giveYearMonth.jsp,该jsp页面使用Tag标记调用ShowCalendar.tag文件,并且向ShowCalendar.tag文件传递年份和月份。

运行效果:

Calendar

jsp日历 bestcoder编程学习网

giveYearMonth.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="rili" %>

<title>Insert title here</title>
</head>
<body>
<p>调用Tag文件来显示日历</p>
<rili:ShowCalendar year="2015" month="10" />
</body>
</html>

ShowCalendar.tag

<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ tag import="java.util.*"%>
<%@ attribute name="year" required="true"%>
<%@ attribute name="month" required="true"%>

<%
int y = 1991;
int m = 1;
String[] day = new String[42];
try {
y = Integer.parseInt(year);
m = Integer.parseInt(month);
Calendar rili = Calendar.getInstance();
rili.set(y, m - 1, 1);
int data = rili.get(Calendar.DAY_OF_WEEK) - 1;
int dayAmount = 0;
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
dayAmount = 31;
if (m == 2 || m == 4 || m == 6 || m == 9 || m == 11)
dayAmount = 30;
if (m == 2)
if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0))
dayAmount = 29;
else
dayAmount = 28;
for (int i = 0; i < data; i++)
day[i] = "--";
for (int i = data, n = 1; i < data + dayAmount; i++) {
day[i] = String.valueOf(n);
n++;
}
for (int i = data + dayAmount; i < 42; i++)
day[i] = "--";

} catch (Exception e) {
out.println("年份或月份不合理。");

}
%>

<h3><%=year%>年<%=month%>月的日历:
</h3>
<table border=1>
<tr>
<th>星期日</th>
<th>星期一</th>
<th>星期二</th>
<th>星期三</th>
<th>星期四</th>
<th>星期五</th>
<th>星期六</th>
</tr>

<%
for (int n = 0; n < day.length; n = n + 7) {
%>
<tr>
<%
for (int i = n; i < 7 + n; i++) {
%>
<td><%=day[i]%></td>
<%
}
%>
</tr>
<%
}
%>
</table>

未经允许不得转载:Bcoder资源网 » jsp日历实现

相关推荐

赞 (0)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册