Done with a calendar marking
Abstract: A marker used to do calendar
</ Td> </ tr> <tr> <td width="531" height="35" valign="top" class="ArticleTeitle"> This is what I learn from a 1.0 jDlog practice. Dlog.tld look at the document:
<? Xml version = "1.0" encoding = "GB2312?">
Taglib PUBLIC "- / / Sun Microsystems, Inc / / DTD JSP Tag Library 1.1 / / EN"
"Http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<bodycontent> Empty </ body>
CalendarTag.java again, and from the property, or request access to parameters
/ *
* Created on 2004-2-6
* /
Package jdlog.tags;
Import java.text.SimpleDateFormat;
Import java.util.Calendar;
Import java.util.Locale;
Import javax.servlet.http.HttpServletRequest;
Import javax.servlet.jsp .*;
Import javax.servlet.jsp.tagext .*;
/ **
* @ Author Liudong
* Tag library calendar
* /
Public class CalendarTag extends TagSupport (
Protected int year = 2005;
Protected int month = 2;
Private final static SimpleDateFormat sdf =
New SimpleDateFormat ( "MMMMM yyyy" Locale.ENGLISH);
Public int doStartTag () (throws JspException
Calendar cal = Calendar.getInstance ();
PageContext.getOut JspWriter out = ();
Try (
If (pageContext.getRequest (). GetParameter ( "paramYear")! = Null) (
Year = Integer.parseInt (pageContext.getRequest (). GetParameter ( "paramYear"));)
If (year> 0)
Cal.set (Calendar.YEAR, year);
) Catch (Exception e) (System.out.println (e.toString ());}
Try (
If (pageContext.getRequest (). GetParameter ( "paramMonth")! = Null) (
Month =
Integer.parseInt (pageContext.getRequest (). GetParameter ( "paramMonth"));)
If (month> 0 & & month <13)
Cal.set (Calendar.MONTH, month-1);
Else if (month == 0) (
Cal.set (Calendar.MONTH, 11);
Cal.add (Calendar.YEAR, -1);
)
Else if (month == 13) (
Cal.set (Calendar.MONTH, 0);
Cal.add (Calendar.YEAR, 1);
)
) Catch (Exception e) ()
Int [] [] = buildCalendar datas (cal);
Try (
Out.print ( "<table border = Ɔ 'width =% Sou' align = 'center' cellspacing = Ƈ '
Cellpadding = Ƈ '> <tr> <td colspan=ƍ'> "+ year +" "+ month +" on </ td> </ tr> <tr> <td
Class = 'week'> Su </ td> <td class='week'> M </ td> <td class='week'> Tu </ td>
<td Class='week'> W </ td> <td
↑ Back Tags: Calendar
Class = 'week'> Th </ td> <td class='week'> F </ td> <td class='week'> Sa </ td> </ tr> ");
For (int i = 0; i
For (int j = 0; j
Out.print ( "</ tr>");
)
Out.print ( "</ table>");
)
Catch (Exception e) (
System.out.println ( "Error");
)
/ / PageContext.setAttribute (datasId, datas);
PageContext.setAttribute ( "year", new Integer (cal.get (Calendar.YEAR)));
PageContext.setAttribute (the "month", new Integer (cal.get (Calendar.MONTH) +1));
/ / PageContext.setAttribute (titleId, sdf.format (cal.getTime ()));
Return SKIP_BODY;
)
/ **
* Constructors calendar
* @ Param year
* @ Param month
* @ Return
* /
Protected static int [] [] buildCalendar (Calendar cal) (
Cal.set (Calendar.DAY_OF_MONTH, 1);
Int firstDateInWeek = cal.get (Calendar.DAY_OF_WEEK) -1;
Int dateOfMonth = getMonthDateCount (cal);
Int base + = dateOfMonth firstDateInWeek;
Int row = base / 7;
Row + = ((base% 7)> 0)? 1:0;
Int [] [] cals = new int [row] [7];
Int iCol = firstDateInWeek, iRow = 0;
For (int i = 1; i <= dateOfMonth; i + +) (
Cals [iCol iRow] [] = i;
If (iCol == 6) (
ICol = 0;
IRow + +;
)
Else
ICol + +;
)
Return cals;
)
/ **
* Designated by the number of days in
* @ Param cal
* @ Return
* /
Protected static int getMonthDateCount (Calendar cal) (
Calendar cal2 = (Calendar) cal.clone ();
Cal2.add (Calendar.MONTH, 1);
Cal2.set (Calendar.DAY_OF_MONTH, 1);
Cal2.add (Calendar.DAY_OF_MONTH, -1);
Return cal2.get (Calendar.DAY_OF_MONTH);
)
Public static void main (String [] args) throws Exception (
Int [] [] = buildCalendar days (Calendar.getInstance ());
For (int i = 0; i
System.out.println ();
)
)
/ **
* @ Return
* /
Public int getMonth () (
Return month;
)
Public int getYear () (
Return year;
)
Public void setMonth (int month) (
This.month = month;
)
Public void setYear (int year) (
This.year = year;
)
)
Third, call jsp
<% @ Page language = "java" contentType = "text / html; GBK charset ="%>
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jstl/core"%>
<% @ Taglib uri = "/ WEB-INF/dlog.tld" prefix = "dlog"%>
<table> <tr> <td Width="200">
<%
Integer year = (Integer) pageContext.getAttribute ( "year");
Integer month = (Integer) pageContext.getAttribute (the "month");
Int nextYear = year.intValue ();
Int lastYear = year.intValue ();
Int next_m month.intValue = () +1;
If (next_m> 12) (
Next_m = 1;
NextYear + +;
)
Int last_m month.intValue = () -1;
If (last_m <1) (
Last_m = 12;
LastYear -;
)
%>
& ParamMonth = <= last_m%%>> on January
& ParamMonth = <= next_m%%>> Next Month
= & ParamMonth
<% = Month.intValue ()%>> last year
= & ParamMonth
<% = Month.intValue ()%>> next year
Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> <td width="176" valign="top" class="ArticleTeitle">
</ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle">
Releated Java Articles
Comments
Leave a Reply






