<%@ page contentType="text/html; charset=gb2312"%>
<%@ page language="java" import="java.util.*,java.sql.*" %>
<jsp:useBean id="db" class="wyxg.db.mysql.mysqlCon" scope="page"/>
<link rel="stylesheet" type="text/css" href="basic.css">
<%! String year;
String month;
int nextMonth,nextYear;
int prevMonth,prevYear;
%>
<%
year =request.getParameter("year");
month=request.getParameter("month");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>jsp日历</title>
</head>
<%! String days[]; %>
<%
days=new String[42];
for(int i=0;i<42;i++)
{
days[i]="";
}
%>
<%
Calendar thisMonth=Calendar.getInstance();
if(month!=null&&(!month.equals("null")))
thisMonth.set(Calendar.MONTH, Integer.parseInt(month) );
if(year!=null&&(!year.equals("null")))
thisMonth.set(Calendar.YEAR, Integer.parseInt(year) );
year=String.valueOf(thisMonth.get(Calendar.YEAR));
month=String.valueOf(thisMonth.get(Calendar.MONTH));
if(month.equals("0"))
{
nextMonth = (Integer.parseInt(month)+1);
nextYear=Integer.parseInt(year);
prevMonth = 11;
prevYear = (Integer.parseInt(year)-1);
}
else if(month.equals("11"))
{
nextMonth = 0;
nextYear = (Integer.parseInt(year)+1);
prevMonth =(Integer.parseInt(month)-1);
prevYear = Integer.parseInt(year);
}
else if(Integer.parseInt(month)>=1 && Integer.parseInt(month)<=10)
{
nextMonth = (Integer.parseInt(month)+1);
nextYear = Integer.parseInt(year);
prevMonth = (Integer.parseInt(month)-1);
prevYear = Integer.parseInt(year);
}
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);
for(int i=0;i<maxIndex;i++)
{
days[firstIndex+i]=String.valueOf(i+1);
}
%>
<body>
<!--FORM name="sm" method="post" action="date2.jsp"-->
<table border="0" width="210" height="81">
<div align=center>
<tr>
<th height="16" colspan="7">
<input type="submit" name="Submit" value="<<" onclick="JavaScript:location.href=’date2.jsp?year=<%=prevYear%>&month=<%=prevMonth%>’">
<%=year%> 年 <%=Integer.parseInt(month)+1%> 月
<input type="submit" name="Submit" value=">>" onclick="JavaScript:location.href=’date2.jsp?year=<%=nextYear%>&month=<%=nextMonth%>’"></th>
</tr>
<tr>
<th width="25" height="16"><font color="red">日</font>
</th>
<th width="25" height="16">一</th>
<th width="25" height="16">二</th>
<th width="25" height="16">三</th>
<th width="25" height="16">四</th>
<th width="25" height="16">五</th>
<th width="25" height="16"><font color="green">六</font></th>
</tr>
<% for(int j=0;j<6;j++) { %>
<tr>
<% for(int i=j*7;i<(j+1)*7;i++) { %>
<td width="25" height="16" valign="middle" align="center">
<%
int nowMonth=(Integer.parseInt(month)+1);
String sql ="select title from article where year=’"+year+"’ and month=’"+nowMonth+"’ and date=’"+days[i]+"’";
ResultSet rs =db.Query(sql);
if(rs.next())
{
%>
<a href="jump.jsp?year=<%=year%>&month=<%=nowMonth%>&date=<%=days[i]%>" title="<%=rs.getString("title")%>"><%=days[i]%></a></td>
<%
}
else
{
%>
<%=days[i]%></td>
<%
}
} %>
</tr>
<% }
%>
</div>
</table>
<!--/FORM-->
</body>
</html>