干脆把我的源代码发上来。总之这个问题不解决,这一天都感觉不舒服。
<jsp:directive.page contentType="text/html;charset=GBK"pageEncoding="UTF-8" />
<%@ page import="*"%>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.DateFormat" %>
<%
//最后要显示年份的第一天,规则为当年的前一年12月26日所在周的第一天。之后在循环显示中calendar代表每次要显示周的第一天(周一)
Calendar calendar=Calendar.getInstance();
//循环显示中代表要显示周的最后一天(周日)
Calendar calendarNext=Calendar.getInstance();
//要显示年份后一年的第一天,规则同calendar
Calendar calendarNextYear=Calendar.getInstance();
//当前年份,用于显示列表框
int thisYear=calendar.get(Calendar.YEAR);
//要显示的年份
int showYear=thisYear;
String showYearString=Integer.toString(showYear);
//要显示年的前一年,既要显示年的第一天所在的年份
int year = showYear-1;
String yearString = Integer.toString(year);
if(request.getParameterValues("yearString")!=null){
showYearString=request.getParameterValues("yearString")[0];
showYear=Integer.parseInt(showYearString);
year=showYear-1;
yearString = Integer.toString(year);
}
//根据year,showYear设置calendar,calendarNextYear
calendar.set(year,11,26);
calendarNextYear.set(showYear,11,26);
//要使calendar和calendarNextYear真正的被设置为需要的状态而必须加上的语句
calendar.get(Calendar.DATE);
calendarNextYear.get(Calendar.DATE);
String weekBeginDateString = DateUtil.getFirstDateOfWeek(calendar);
String weekBeginDateStringNextYear = DateUtil.getFirstDateOfWeek(calendarNextYear);
String weekBeginDateStrings[] = weekBeginDateString.split("-");
String weekBeginDateStringsNextYear[] = weekBeginDateStringNextYear.split("-");
int tempYear = Integer.parseInt(weekBeginDateStrings[0]);
int tempMonth = Integer.parseInt(weekBeginDateStrings[1]) - 1;
int tempDay = Integer.parseInt(weekBeginDateStrings[2]);
int tempYearNextYear = Integer.parseInt(weekBeginDateStringsNextYear[0]);
int tempMonthNextYear = Integer.parseInt(weekBeginDateStringsNextYear[1]) - 1;
int tempDayNextYear = Integer.parseInt(weekBeginDateStringsNextYear[2]);
calendar.set(tempYear, tempMonth, tempDay);
calendarNext.set(tempYear, tempMonth, tempDay);
calendarNextYear.set(tempYearNextYear, tempMonthNextYear, tempDayNextYear);
%>
<br/>
<form action="lookPlanByWeekView" method="post">
<font size="4" class="viewtitle"><b>选择年份</b></font>
<select name="yearString" onchange="javascript:this.parentNode.submit()">
<%
for(int i=2003;i<=thisYear;i++){
String thisShowYearString=Integer.toString(i);
if(i==showYear){
%>
<option value="<%=thisShowYearString%>" selected><%=i%>年</option>
<%
}
else{
%>
<option value="<%=thisShowYearString%>"><%=i%>年</option>
<%
}
}
%>
</select>
</form>
<hr align="left" width="98%">
<div align="center"><h3><%=Integer.toString(showYear)%>年 公司计划周度索引</h3></div>
<table style="TEXT-ALIGN: center;border-collapse:collapse;" border="1" align="center">
<%
//每行显示数
int number=6;
for(int i=0;;i++){
calendarNext.add(Calendar.DAY_OF_MONTH, 6);
if((calendarNextYear)<0){
String thisBeginDate=DateUtil.getStringFromCalendar(calendar);
String thisEndDate=DateUtil.getStringFromCalendar(calendarNext);
if(i%number==0){
%>
<tr>
<%
}
%>
<td>
<a target="_blank" href="companyWeekPlans?currentDate=<%=thisBeginDate%>" >
<font size=3><%=showYearString%>年 第<%=(i+1)%>周</font>
<br/>
</a>
(<%=thisBeginDate%>~<%=thisEndDate%>)
</td>
<%
if(i%number==(number-1)){
%>
</tr>
<%
}
calendar.add(Calendar.DAY_OF_MONTH, 7);
calendarNext.add(Calendar.DAY_OF_MONTH, 1);
}
else
break;
}
%>
</table>
红色的部分就是我提到的后加上的部分
[[it] 本帖最后由 wubaodong 于 2008-5-5 16:25 编辑 [/it]]