SoFunction
Updated on 2025-04-05

A calendar program implemented with JSP


<!-- Displays the calendar for any year and month, and you can select different years and months. author:wildfield -->
<%@ page language="java" import=".*" %> 
<%! String year; 
  String month; 
%> 
<% month=("month"); 
  year =("year"); 
%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>day</title>
<script Language="JavaScript"> 
<!-- 
function changeMonth() 

var mm="?month="+[0].selectedIndex+"&year=" 
+<%=year%>; 
(mm,"_self"); 

//--></script> 
</head> 
<%! String days[]; %> 
<% 
days=new String[42]; 
for(int i=0;i<42;i++) 
 { 
  days[i]=""; 
 } 
%> 
<% 
Calendar thisMonth=(); 
 if(month!=null&&(!("null"))) 
  (, (month) ); 
 if(year!=null&&(!("null"))) 
  (, (year) ); 
 year=(()); 
month=(()); 
(); 
(Calendar.DAY_OF_MONTH,1); 
int firstIndex=(Calendar.DAY_OF_WEEK)-1; 
int maxIndex=(Calendar.DAY_OF_MONTH); 
for(int i=0;i<maxIndex;i++) 
 { 
  days[firstIndex+i]=(i+1); 
 } 
%> 
<body> 
<FORM name="sm" method="post" action=""> 
<%=year%>year  <%=(month)+1%>month
<table border="0" width="168" height="81"> 
<div align=center> 
 <tr> 
<th width="25" height="16" bgcolor="#FFFF00"><font color="red">day</font>
</th> 
<th width="25" height="16" bgcolor="#FFFF00">one</th>
<th width="25" height="16" bgcolor="#FFFF00">two</th>
<th width="25" height="16" bgcolor="#FFFF00">Three</th>
<th width="25" height="16" bgcolor="#FFFF00">four</th>
<th width="25" height="16" bgcolor="#FFFF00">five</th>
<th width="25" height="16" bgcolor="#FFFF00"><font color="green">Six</fon
t></th> 
 </tr> 
<% for(int j=0;j<6;j++) { %> 
<tr> 
     <% for(int i=j*7;i<(j+1)*7;i++) { %> 
    <td width="15%" height="16" bgcolor="#C0C0C0" valign="middle" align="ce 
nter"> 
    <a href="?year=<%=year%>&month=<%=(month)+1%>&d 
ate=<%=days[i]%>" target="main"><%=days[i]%></a></td> 
   <% }  %> 
 </tr> 
<% }  %> 
</div> 
</table> 
<table border="0" width="168" height="20"> 
<tr> 
 <td width=30%><select name="month" size="1" onchange="changeMonth()" > 
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
 </select></td> 
<td width=28%><input type=text name="year" value=<%=year%> size=4 maxlength 
=4></td> 
<td>year</td>
<td width=28%><input type=submit value="Submit"></td>
</tr> 
</table> 
</FORM> 
<script Language="JavaScript"> 
<!-- 
 =<%=month%>; 
//--> 
</script> 
</body> 
</html>