用JSP實現的行事曆程式__JSP

來源:互聯網
上載者:User

JSP實現的行事曆程式

 

鐵樹

tieshu

rngguliu@163.com

2006年4月4日星期二

可顯示任意年月,當前日加有背景色,周末為紅色。本行事曆程式是本人議程管理程式中的一部分(附議程管理的效果圖)。 1 效果圖

議程管理的效果圖

2 JSP代碼

<body>

<jsp:useBean id="bean" class="general.CanlendarFace"/>

<%

String year, month, date;

        year = request.getParameter("year");

        month = request.getParameter("month");

        date = request.getParameter("date");

        out.println(bean.showHtml(year,month,date));

%>

</body>

3 JavaBean代碼

/**

 * @author 鐵樹

 */

package general.calendar;

import java.util.*;

public class CanlendarFace {

    public String showHtml(String year, String month, String date) {

        int y, m, d;

        GregorianCalendar  temp= new GregorianCalendar ();//取得當前的日曆(格裡高裡曆)

        try {

            y = Integer.parseInt(year);

            m = Integer.parseInt(month);

            d = Integer.parseInt(date);

        } catch (Exception e) {          

            y = temp.get(GregorianCalendar.YEAR); //取得年份 ;

            m = temp.get(GregorianCalendar.MONTH); //取的月份

            d = temp.get(GregorianCalendar.DAY_OF_MONTH); //取的當前日

        }

        if (y<1900 ||y>9999) y=temp.get(GregorianCalendar.YEAR); //取得年份 ;

        if (m==-1){

        y--;

        m=11;

        }else if(m==12){

        y++;

        m=0;

        }else if(m<-1 || m>12){

         m = temp.get(GregorianCalendar.MONTH); //取的月份

        }        

        if (d<1 || d>31) d=1;//預設日       

        Calendar thisMonth = Calendar.getInstance();

        thisMonth.set(y, m, d);

        thisMonth.setFirstDayOfWeek(Calendar.SUNDAY);

        thisMonth.set(Calendar.DAY_OF_MONTH, 1);

        int firstIndex = thisMonth.get(Calendar.DAY_OF_WEEK) - 1;

        int maxIndex = thisMonth.getActualMaximum(Calendar.DAY_OF_MONTH);

        String[] days = new String[42];

        for (int i = 0; i < 42; i++) { //初始化表格式資料

            days[i] = "&nbsp;";

        }

        for (int i = 0; i < maxIndex; i++) { //初始化具有實際日期值得部分

            days[firstIndex + i] = String.valueOf(i + 1);

        }

        String face = "";

        face += "<table id=/"t1/" width=/"91%/" border=/"1/" align=/"center/" cellpadding=/"2/" cellspacing=/"1/" bordercolordark=/"#94CCF6/" bordercolorlight=/"#fefefe/">";

        face += "<tr>";

        face += "<td height=/"35/" colspan=/"7/" align=/"center/" bgcolor=/"#CAE8FF/">";

        face += "<a href=/"daily.jsp?year="+(y-1)+"&month="+m+"&date=1/">上一年</a>&nbsp;";

        face += "<a href=/"daily.jsp?year="+y+"&month="+(m-1)+"&date=1/">上一月</a>";

        face += "<strong class=/"STYLE4/"> " + y + " 年 " + (m +1) + "  月 </strong>";//"+d +" 日

        face += "<a href=/"daily.jsp?year="+y+"&month="+(m+1)+"&date=1/">下一月</a>&nbsp;";

        face += "<a href=/"daily.jsp?year="+(y+1)+"&month="+m+"&date=1/">下一年</a>";

        face += "</td></tr>";

        face += "<tr>";

        face += "<td width=/"14%/" align=/"center/" bgcolor=/"#C8E1FA/"><span class=/"STYLE3/">日</span></td>";

        face += "<td width=/"14%/" align=/"center/" bgcolor=/"#C8E1FA/">一</td>";

        face += "<td width=/"14%/" align=/"center/" bgcolor=/"#C8E1FA/">二</td>";

        face += "<td width=/"14%/" align=/"center/" bgcolor=/"#C8E1FA/">三</td>";

        face += "<td width=/"14%/" align=/"center/" bgcolor=/"#C8E1FA/">四</td>";

        face += "<td width=/"14%/" align=/"center/" bgcolor=/"#C8E1FA/">五</td>";

        face += "<td align=/"center/" bgcolor=/"#C8E1FA/"><span class=/"STYLE3/">六</span></td>";

        face += "</tr>";

 

        for (int j = 0; j < 6; j++) {

            face += "<tr id=/"line"+ j +"/">";

            String status = "status=yes,scrollbars=yes,resizable=yes,width=640,height=480";

            for (int i = j * 7; i < (j + 1) * 7; i++) {

              if (i==35 && days[i].equals("&nbsp;")){

                   face += "<script>line5.style.display=/"none/"</script>";//"<td>&nbsp;</td>";

                   break;

              }

              if (days[i].equalsIgnoreCase(String.valueOf(temp.get(GregorianCalendar.DAY_OF_MONTH)))&& y == temp.get(GregorianCalendar.YEAR) && m == temp.get(GregorianCalendar.MONTH)){

                       face += "<td bgcolor=/"#E7FEE8/" height=/"50/" align=/"center/" <span class=/"STYLE10/">";

              }else if ((i%7)==0 || ((i+1)%7)==0){

                   face += "<td height=/"50/" align=/"center/" <span class=/"STYLE6/">";

              }else{

                   face += "<td height=/"50/" align=/"center/" <span class=/"STYLE7/">";

              }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.