Implement a monthly calendar on a JSP Web page

Source: Internet
Author: User
Tags implement
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>




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.