Implement calendar on jsp (preferred for SUN Enterprise Applications) web pages
Jsp (preferred for SUN Enterprise applications) and calendar
<% @ Page contentType = "text/html; charset = gb2312" language = "java" import = "java. util. *, java. text. *" %>
<Html>
<Head>
<Title> calendar </title>
</Head>
<Body style = "font-size: 12px">
<%!
/* Declare the variable */
String [] months = {"January", "February", "March", "l", "May", "June ",
"July", "August", "September", "October", "November", "December "};
String [] months_cn = {"August", "August ",
"August", "August "};
Public final static int dom [] = {
31, 28, 31, 30,
31, 30, 31, 31,
30, 31, 30, 31
};
%>
<%
/* Handle 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 unavailable ");
}
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 (preferred for SUN Enterprise Applications)">
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> enter the Year:
<Input type = "text" size = "5" name = "year" value = "<% = yy %>"> & nbsp;
<Input type = "submit" value = "display">
</Form>
<%
Int lead = 0;
%>
<Table border = "0" cellpadding = "1" cellspacing = "1" style = "font-size: 12px">
<Tr height = "20"> <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>