A JSP program about the calendar! __jsp

Source: Internet
Author: User

A Jsp+javabeans implementation of the Web calendar program, mainly using the Calendar class.
Monthbean.java
Package test;
Import Java.text.DateFormat;
Import Java.text.DateFormatSymbols;
Import java.util.*;

public class Monthbean {
Public final static int[]daysinmonth={31,28,31,30,31,30,31,31,30,31,30,31};
public String []monthnames=null;
protected DateFormatSymbols symbols=null;
Protected Calendar cal=calendar.getinstance ();
protected int Today=cal.get (calendar.day_of_month);
protected int Month=cal.get (calendar.month);
protected int Year=cal.get (calendar.year);

Public Monthbean () {
Symbols=new DateFormatSymbols ();
Monthnames=symbols.getmonths ();
}
public void setmonth (int montharg) {
This.month=montharg;
}
public void setyear (int yeararg) {
This.year=yeararg;
}
public void Setmonth (String montharg) {
try{
int Month=integer.parseint (MONTHARG);
Setmonth (month);
}catch (Exception exc) {
}
}
public void Setyear (String yeararg) {
try{
int Year=integer.parseint (YEARARG);
Setyear (year); }catch (Exception exc) {
}
}
Public String Getmonthname () {
Return Monthnames[cal.get (Calendar.month)];
}
public int Gettoday () {
return to today;
}
public int Getstartcell () {
Calendar beginofmonth=calendar.getinstance ();
Beginofmonth.set (year,month,0);
Return Beginofmonth.get (Calendar.day_of_week);
}
public int Getendcell () {
Cal.set (year,month,1); int Endcell=daysinmonth[month]+getstartcell ()-1;
if (month==calendar.february && (GregorianCalendar) cal). Isleapyear (year)) {
endcell++;
}
return Endcell;
}
public void Update () {
Cal.set (this.year,this.month,1);
}
Public String getdayname (int day,boolean longformat) {
if (Longformat)
return symbols.getweekdays () [Day];
return symbols.getshortweekdays () [Day];
}
}

month.jsp
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "Test.monthbean"%>
<jsp:usebean id= "cal" class= "Test.monthbean" scope= "Request"/>
<%
int Today=cal.gettoday ();
%>
<title>
Calendar
</title>
<body bgcolor= "Silver" ><br><br><br>
<table border= "1" align= "center" width= "40%" height= "a" ><tr bgcolor= "Silver" >
&LT;TD colspan= "7" >&nbsp;<font size= "+2" >
<%=cal.getmonthname ()%>
</font></td></tr>
<tr bgcolor= "BLACK" align= "center" >
<% for (int i=1;i<8;i++) {
Out.print ("<td width=/" 70/">");
Out.print ("<font size/" -1/"color=/" white/">");
Out.print (Cal.getdayname (i,true));
Out.print ("</front> </td>");
}%>
</tr>
<% int Startcell=cal.getstartcell ();
int Endcell=cal.getendcell ();
for (int cellno=0,day=1;cellno<42;cellno++) {
if (cellno%7==0) {out.print ("<tr>");}
Out.print ("<td valign=top height=57");
if (cellno<startcell| | Cellno>endcell) {
Out.print ("bgcolor=/" gray/">"); }
else {
if (day==today) {//If the background color is set to green for the current date
Out.print ("bgcolor=/" green/">");
}
Else
Out.print (">");
%>
<%=day%>
<%
day++;
}
Out.println ("</td>");
if (cellno+1%7==0) {
Out.print ("</tr>"); }
}//end for Loop
%>

</table>

</body>

The effect of the following figure:


 

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.