public static String getReqParameter(String Req, String ifNulltoReplace) {
if ( Req == null || Req.equals("")) return ifNulltoReplace;
else return Req.trim();
}
public static String getReqParameter(String Req) {
if (Req == null || Req.equals("")) return "";
else return Req.trim();
}
public static int getIntParameter(String Req, int ifNulltoReplace) {
try {
if ( Req == null || Req.equals("")) return ifNulltoReplace;
else return Integer.parseInt(Req.toString());
}catch(NumberFormatException e){
return ifNulltoReplace;
}
}
public static int getIntParameter(String Req) {
try {
if (Req == null || Req.equals("")) return 0;
else return Integer.parseInt(Req.toString());
}catch(NumberFormatException e){
return 0;
}
}
<%@ page language="java" pageEncoding="EUC-KR" %>
<%@ page import="java.util.*" %>
<%
Calendar today = Calendar.getInstance();
Calendar firstday = Calendar.getInstance();
Calendar lastday = Calendar.getInstance();
int toYear = getIntParameter(request.getParameter("year"),today.get(Calendar.YEAR));
int toMonth = getIntParameter(request.getParameter("month"),today.get(Calendar.MONTH)+1);
out.println("<center>"+toYear +"/"+ toMonth+"</center><br>");
firstday.set(toYear,toMonth-1,1);
lastday.set(toYear,toMonth,1);
lastday.add(Calendar.DATE,-1); //해당월의 마지막 날짜
%>
<html>
<head>
<title>Calendar</title>
</head>
<body bgcolor="#FFFFFF">
<table border=1 width=90% align=center>
<tr height=30 align=center bgcolor=#929292>
<td><font color=red><b>일</b></font></td>
<td>월</td>
<td>화</td>
<td>수</td>
<td>목</td>
<td>금</td>
<td><font color=blue><b>토</b></font></td>
</tr>
<%
int jcount = (int)Math.ceil((double)(lastday.get(Calendar.DATE)-1 + firstday.get(Calendar.DAY_OF_WEEK)) / 7);
int count = 2; // 첫번째 요일까지 공백 때분에...
int _day = 0;
String bgcolor = "";
for(int ju=0;ju<jcount;ju++){
out.println("<tr>");
for(int i=0;i<7;i++){
switch(i){
case 0 : bgcolor="#FFD7D7";break;
case 6 : bgcolor="#C1C1FF";break;
default : bgcolor="#E7E7E7";break;
}
if(firstday.get(Calendar.DAY_OF_WEEK) < count){
_day = count - firstday.get(Calendar.DAY_OF_WEEK);
if( _day > lastday.get(Calendar.DATE)) _day = 0;
}
count ++;
out.println("<td height=100 valign=top bgcolor='"+bgcolor+"'>"+_day+"</td>");
}
out.println("</tr>");
}
%>
</body>
</html>