JAVABEAN:
package com.calendar;
import java.util.Calendar;
public class test {
Calendar calendar = Calendar.getInstance();
int year=calendar.get(Calendar.YEAR);
int month=calendar.get(Calendar.MONTH)+1;
int firstDay=getFirstDayOfMonth(year,month);
int day=getDay();
int monthlength=getMonthLength(year,month);
String[] s = new String[monthlength+firstDay];
int i=0,j=1;
public String[] getCalendar()
{
System.out.println("date:"+day);
for(i=firstDay;i<(firstDay+monthlength);i++)
{
if(j<=monthlength){
s[i]=j+"";
j++;
}
else{
break;
}
}
return s;
}
private int getMonthLength(int y,int m)
{
if(m==2)
{
if((y%4==0)&&(y%100!= 0)||(y%400==0))
monthlength=29;
else
monthlength=28;
}
else if(m==4||m==6||m==9||m==11)
monthlength=30;
else
monthlength=31;
return monthlength;
}
private int getDay()
{
day=calendar.get(Calendar.DATE);
return day;
}
private int getFirstDayOfMonth(int y,int m)
{
calendar.set(y,m-1,1);
firstDay=calendar.get(Calendar.DAY_OF_WEEK);
return firstDay;
}
}
页面部分:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<jsp:useBean id="date" scope="page" class="com.calendar.test" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JSP日历</title>
</head>
<body>
<%
int j=1;
String ss[]= date.getCalendar();
%>
<table align="center" width="140">
<tr>
<td width="20">日</td>
<td width="20">一</td>
<td width="20">二</td>
<td width="20">三</td>
<td width="20">四</td>
<td width="20">五</td>
<td width="20">六</td>
</tr>
<%
for(int z=1;z<ss.length;z++)
System.out.println("ss["+z+"]="+ss[z]);
out.print("<tr>");
for(int i=1;i<ss.length;i++)
{
if(j<=7)
{
if(ss[i]==null)
out.print("<td>"+" "+"</td>");
else
out.print("<td>"+ss[i]+"</td>");
j++;
}
else
{
out.print("</tr><tr>");
i--;
j=1;
}
}
out.print("</tr>");
%>
</table>
</body>
</html>
分享到:
相关推荐
caltest
6. 测试程序(CALTEST.EXE):用于测试DLL功能的可执行文件。 7. 头文件(CALENDAR.H):包含了DLL的函数原型和结构定义,供外部程序引用。 8. 头文件(EXAMPLE.H):可能包含了示例程序的函数和常量定义。 9. 帮助...