好的,所以我正在开发一个显示所选年份的事件的 JSP。It works fine for 2012, but when 2013 is selected it doesn't work. 可能是因为那里没有数据,但仍应显示月份。
请记住,我是 CS 大二的实习生
这是填充月份数组列表的方法。
public List getMonths() {
List months = new ArrayList();
Map tempMap = new HashMap();
tempMap.put("month", "January");
tempMap.put("value", 1);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "February");
tempMap.put("value", 2);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "March");
tempMap.put("value", 3);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "April");
tempMap.put("value", 4);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "May");
tempMap.put("value", 5);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "June");
tempMap.put("value", 6);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "July");
tempMap.put("value", 7);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "August");
tempMap.put("value", 8);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "September");
tempMap.put("value", 9);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "October");
tempMap.put("value", 10);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "November");
tempMap.put("value", 11);
months.add(tempMap);
tempMap = new HashMap();
tempMap.put("month", "December");
tempMap.put("value", 12);
months.add(tempMap);
tempMap = new HashMap();
return months;
}
然后我使用这段代码来设置属性:
request.setAttribute("months", getMonths());
request.setAttribute("parkEvents", parkEventsList);
request.setAttribute("parkYears", parkYearsList);
request.setAttribute("currentYear", year);
这是应该显示月份的 JSTL 代码,但似乎循环 "c:forEach var="months" items="${months}" 在 2013 年没有迭代。有什么想法吗?
<div>
<form>
<select onchange="javascript:window.open(this.value,'_self')">
<c:forEach var="years" items="${parkYears}">
<option value=/events.html?display_year=${years}<c:if test="${currentYear == years}"> selected="selected"</c:if>>${years}</option>
</c:forEach>
</select>
</form>
</div>
<c:set var="years" value="${currentYear}"/>
<div class="generaltext">
<!-- begin accordion -->
<div class="accordion" id="${years}" style="margin-top: 20px; display: none;"><!-- begin fas section -->
<c:forEach var="months" items="${months}">
<div class="section">
${years}
<div class="sectionHeader inactiveHeader" id="${months.value}${years}SectionHeader">
<a onclick="_showSectionContentContainer('${months.value}${years}Section'); return false;" href="#">
<img id="${months.value}${years}SectionArrow_down" alt="" src="/export/resources/images/arrows/grayRightSmall.gif" />
<img id="${months.value}${years}SectionArrow_right" alt="" style="display: none;" src="/export/resources/images/arrows/grayDownSmall.gif" />${months.month} ${years}</a>
</div>
<div class="sectionContent" id="${months.value}${years}Section" style="display: none;"><br/>
<c:set var="counter" value="0" />
<c:forEach var="event" items="${parkEvents}">
<c:if test="${event.eventYear == years && event.eventMonth == months.value && event.eventDay != counter}">
</br><b> ${event.eventMonth}/${event.eventDay}/${event.eventYear}</b></br>
<c:set var="counter" value="${event.intEventDay}" />
</c:if>
<c:if test="${event.eventYear == years && event.eventMonth == months.value && event.eventDay == counter}">
- <a target="_blank" href="http://fwp.mt.gov/eCalendar/ViewItem.html?cal_item_id=${event.id}&dtwhen=${event.intStartingDate}">${event.description} </a><br/>
</c:if>
</c:forEach>
</div>
</div>
</c:forEach>
</div> <!-- end accordion -->
</div>