加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

网页日历编程技术:JSP+JAVABEANS

发布时间:2023-06-03 13:30:11 所属栏目:教程 来源:
导读:一个jsp+javabeans实现的web日历程序,主要使用了calendar类!

monthbean.java

package test;

import java.text.dateformat;

import java.text.dateformatsymbols;

import java.util.*;

pub
一个jsp+javabeans实现的web日历程序,主要使用了calendar类!
 
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.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();
 
%>
 
<html>
 
<head>
 
<title>
 
日历
 
</title>
 
</head>
 
<body bgcolor="silver" ><br><br><br>
 
<table border="1" align="center" width="40%" height="100"><tr bgcolor="silver" >
 
<td colspan="7"> <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){  //如果为当前日期,背景色设为绿色
 
                   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>
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!