Calendarbean.java
Package Red.star; Import java.util.*; public class Calendarbean {String calendar = null, int year = 1,month =-1; public void setyear (int year) {this.year = y Ear public int getyear () {return year;} public void setmonth (int month) {this.month = month;} public int getmonth () {RE Turn month; Public String Getcalendar () {StringBuffer buffer = new StringBuffer (); Calendar Rili = Calendar.getinstance (); Rili.set (year,month-1,1); Turn the day calendars to year month month 1st, note 0 for January, with this kind of push 11 means December/Get 1st is the week (Get method return value is 1 for Sunday, the return value is 7 for Saturday) int Weeks = Rili.get (Calendar.day_of_week)-1; int day = 0; if (month==1| | month==3| | month==5| | month==7| | month==8| |month==10| | month==12 {day =;} if (month==4| | month==6| | month==9| | month==11) {day =} if (month==2) {if ((year%4==0) && (year%100!=0)) | | (year%400==0)) {day = 29;} else {day = 28;}} String A [] = new string[42]; for (int i=0;i< weeks; i++) {A[i] = "* *";} for (int i= weeks,n=1;i< weeks +day;i++) {A[i] = string.valueof (n); n++;} for (int I= weeks +day;i<42;i++) {A[i] = "* *";///////Buffer.append ("<table border=1>"); Buffer.append ("<tr>"); String Weekday [] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; for (int k=0;k<7;k++) {buffer.append ("<td>" +weekday[k]+ "</td>");} buffer.append ("</tr>"); for (int k=0;k<42;k=k+7) {buffer.append (' <tr> '); for (int j=k;j<math.min (7+K, N), J + +) {buffer.append (" <TD align=center> "+a[j]+" "</td>"); } buffer.append ("</tr>"); } buffer.append ("</table>"); Calendar = new String (buffer); return calendar; } }
Showcalendar.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "BIG5"%> <% String Path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/"; %> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >