A calendar JSP program!

Source: Internet
Author: User

A JSP + JavaBeans web calendar program mainly uses 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 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. getreceivweekdays () [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 ();
%>
<HTML>
<Head>
<Title>
Calendar
</Title>
</Head>
<Body bgcolor = "Silver"> <br>
<Table border = "1" align = "center" width = "40%" Height = "100"> <tr bgcolor = "Silver">
<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 it is the current date, the background color is set to green
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>
</Html>

 

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.