Implement calendar on JSP web pages

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.