<%@ page import="java.util.*,java.text.*,java.net.*" %>
<html>
<head><title>Calendar</title></head>
<body bgcolor="white">
<font size=3>
<%

Calendar calendar;
Calendar today = new GregorianCalendar(); int dayOfWeek;
int lastDayOfMonth;
Date date;
SimpleDateFormat sdf;

String action = request.getParameter("action"); if (action == null || action.equals("")) {

calendar = new GregorianCalendar(); }
else
{ action = URLDecoder.decode(action); calendar = (Calendar)session.getAttribute("calendar"); calendar.set(Calendar.DATE, 1); if (action.equals("<<")) { calendar.add(Calendar.MONTH, -1); } else // action.equals(">>") { calendar.add(Calendar.MONTH, 1); }

}

session.setAttribute("calendar", calendar); lastDayOfMonth = calendar.getActualMaximum(Calendar.DATE); %>
<center>
<form method=POST action=Calendar.jsp>
<table>
<tr>
<th align=right><input type=submit name=action value="<<"> <%

date = calendar.getTime();
sdf = new SimpleDateFormat("MMM yyyy"); %>
<th><%= sdf.format(date) %>
<th align=left><input type=submit name=action value=">>"> </table>
</form>
<form method=POST action=Caller.jsp>
<table border=1>
<tr align=center>
<th><font color="red">Su</font>
<th>Mo
<th>Tu
<th>We
<th>Th
<th>Fr
<th><font color="red">Sa</font>
<tr align=center>
<%

calendar.set(Calendar.DATE, 1);
dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

// display initial blank spaces
for (int blank=Calendar.SUNDAY; blank<dayOfWeek; blank++) {
%>
<td>&nbsp;
<%

}

sdf = new SimpleDateFormat("dd");

// display days of the current month for (int day=1; day<=lastDayOfMonth; day++) { calendar.set(Calendar.DATE, day); dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); date = calendar.getTime(); if ((today.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) && (today.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)) && (today.get(Calendar.DATE) == calendar.get(Calendar.DATE))) { // this only works in Linux but not in Windows platform

%>
<td><b><font color="blue"><input type=submit name=day value=<%= sdf.format(date) %>></font></b> <% } else if ((calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY)) { // this only works in Linux but not in Windows platform

%>
<td><font color="red"><input type=submit name=day value=<%= sdf.format(date) %>></font> <% } else {

%>
<td><input type=submit name=day value=<%= sdf.format(date) %>> <%

} // begins a new row after every Saturday if (calendar.get(Calendar.DAY_OF_WEEK) % 7 == 0) {

%>
<tr align=center>
<%

}
}

// display final blank spaces
for (int blank=dayOfWeek+1; blank<=Calendar.SATURDAY; blank++) {
%>
<td>&nbsp;
<%

}

sdf = new SimpleDateFormat("yyyy"); %>
<input type=hidden name=year value=<%= sdf.format(date) %>> <%

sdf = new SimpleDateFormat("MM");
%>
<input type=hidden name=month value=<%= sdf.format(date) %>> </table>
</form>
</center>
</font>
</body>
</html>