Implement a monthly calendar on a JSP Web page
Last Update:2017-02-28
Source: Internet
Author: User
js| Web page to implement a monthly calendar on a JSP page
JSP, monthly calendar
<%@ page contenttype= "text/html; charset=gb2312 "language=" java import= "java.util.*,java.text.*"%>
<title> Calendar </title>
<body style= "font-size:12px" >
<%!
/* Declaration Variable * *
string[] months = {"January", "February", "March", "April", "may", "June",
"July", "August", "September", "October", "November", "December"};
String[] Months_cn = {"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"};
Public final static int dom[] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31.
};
%>
<%
/* Handling Events/*
Boolean yyok = false;
int yy = 0, mm = 0;
String yystring = Request.getparameter ("year");
if (yystring!= null && yystring.length () >0) {
try {
Yy=integer.parseint (yystring);
Yyok=true;
}
catch (NumberFormatException e) {
OUT.PRINTLN ("Year not available");
}
Calendar cal = Calendar.getinstance ();
if (!yyok)
yy = Cal.get (calendar.year);
String mmstring = Request.getparameter ("month");
if (mmstring = = null) {
MM = Cal.get (calendar.month);
}
else {
for (int i = 0; i < months.length; i++)
if (Months[i].equals (mmstring)) {
MM = i;
Break
}
}
}
%>
<form name= "cal" Method=post action= "cal.jsp" >
Please select month:
<select name= "Month" >
<%
/* Initialize the form/*
for (int i = 0; i < months.length; i++) {
if (i = = mm)
Out.print ("<option selected value=january>");
Else
Out.print ("<option value=" +months[i]+ ">");
Out.print (Months_cn[i]);
Out.print ("</option>");
}
%>
</select>
<br> Please enter the year:
<input type= "Text" size= "5" name= "Year" value= "<%=yy%>" >
<input type= "Submit" value= "Show" >
</form>
<%
int lead = 0;
%>
<table border= "0" cellpadding= "1" cellspacing= "1" style= "font-size:12px" >
<tr height= "><td colspan=" 7 "><font color=" #3399FF "><b><%= months[mm]%> <%= yy% ></b></font></td></tr>
<% GregorianCalendar calendar = new GregorianCalendar (yy, MM, 1); %>
<tr><td><font color= "#FF0000" >Sun</font></td><td>Mon</td><td> Tue</td><td>wed</td>
<td>thu</td><td>fri</td><td><font color= "#FF0000" >sat</font></td ></tr>
<%
/* Below is the code to display the monthly calendar * *
Lead = Calendar.get (Calendar.day_of_week)-1;
int dayinmonth = dom[mm];
if (Calendar.isleapyear (Calendar.get (calendar.year)) && mm = = 1)
++dayinmonth;
Out.print ("<tr>");
for (int i = 0; i < leads; i++) {
Out.print ("<td> </td>");
}
for (int i = 1; I <= dayinmonth; i++) {
if ((i+lead)% 7 = 0 | | (i+lead)% 7 = 1)
Out.print ("<td align=\" Center\ "><font color=\" #FF0000 \ ">" +i+ "</font></td>");
Else
Out.print ("<td align=\" Center\ ">" +i+ "</td>");
if ((lead+i)% 7 = 0) {
Out.print ("</tr></tr>");
}
}
Out.print ("</tr>");
%>
</table>
</body>