Skip to content

Instantly share code, notes, and snippets.

@nissuk
Created November 23, 2011 11:07
Show Gist options
  • Save nissuk/1388443 to your computer and use it in GitHub Desktop.
Save nissuk/1388443 to your computer and use it in GitHub Desktop.
JSP: 単純なカレンダーを出力する(タグファイル)
<%@tag pageEncoding="UTF-8" body-content="empty"%>
<%@tag import="java.util.Calendar"%>
<%@attribute name="year" type="Integer" required="true" rtexprvalue="true" %>
<%@attribute name="month" type="Integer" required="true" rtexprvalue="true" %>
<%
Calendar cal = Calendar.getInstance();
cal.set(year, month - 1, 1);
int firstDayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
int day = 2 - firstDayOfWeek;
%><table><%
for (int row = 0; row < 6; row++) {
%><tr><%
for (int col = 0; col < 7; col++) {
%><td><%= (1 <= day && day <= lastDay) ? day : "&nbsp;" %></td><%
day++;
}
%></tr><%
}
%></table>
@nissuk
Copy link
Author

nissuk commented Dec 23, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment