0
上有一個JSP頁面這樣的:我如何防止過相同的屬性迭代jsp頁面
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Page for find kids</title>
</head>
<body>
<a href="#" id="shlink"><h3 align="center">Parameters of search</h3></a>
<form:form action="result" method="get" modelAttribute="fbosAttribute" >
<table id="searchForm" align="center">
<tr id="dateId">
<th>Date:</th>
<td><form:select path="particularDate">
<form:option value=""> -Выберите дату-</form:option>
<form:options items="${listOfDates}"></form:options>
</form:select> <td><font color="#FF0000"><b><form:errors path="particularDate"/></b> </font></td>
</td>
</tr>
<tr id="nameId">
<th>Name:</th>
<td><form:select path="nameOfInstitution">
<form:option value=""> -Выберите учреждение-</form:option>
<form:options items="${listOfInstitutionsNames}"></form:options>
</form:select></td> <td><font color="#FF0000"><b><form:errors path="nameOfInstitution"/></b></font></td>
</tr>
<tr id="typeId">
<th>Type:</th>
<td>
<form:select path="typeOfInstitution">
<form:option value=""> -Выберите тип-</form:option>
<form:options items="${listOfInstitutionsTypes}"></form:options>
</form:select> </td> <td><font color="#FF0000"><b><form:errors path="typeOfInstitution"/></b></font></td>
</tr>
<tr>
<td>
<input type="submit" value="Find" id="searchBtn" />
</td>
</tr>
</table>
</form:form>
<c:choose>
<c:when test="${empty dateAttribute}">
<h1 align="center">Insert parameterst for search</h1>
</c:when>
<c:otherwise>
<table align="center" border="1" id="resultTable">
<thead>
<tr>
<th>Name of school</th>
<th>Type</th>
<th>Particular date</th>
<th>Day Scheduale</th>
<th>Work Scheduale</th>
<th>Rotation</th>
<th>Number of kids</th>
<th>Kids upper 3 years old</th>
<th>Kids under 3 years old</th>
<th>Kids go to school date </th>
<th>Kids admitted date</th>
</tr>
</thead>
<c:forEach items="${institutionAttribute}" var="institutionVar">
<c:forEach items="${dateAttribute}" var="creationDateVar">
<c:forEach items="${srcAttribute}" var="schRotChildVar">
<tr>
<td align="center">${institutionVar.nameOfInstitution}</td>
<td align="center">${institutionVar.typeName}</td>
<td align="center">${creationDateVar.particularDate} </td>
<td align="center">${schRotChildVar.dayScheduale}</td>
<td align="center">${schRotChildVar.workScheduale}</td>
<td align="center">${schRotChildVar.rotation}</td>
<td align="center">${schRotChildVar.numberOfChild}</td>
<td align="center">${schRotChildVar.childUnder3YearsOld}</td>
<td align="center">${schRotChildVar.childUpper3YearsOld}</td>
<td align="center"><fmt:formatDate value="${creationDateVar.childGoSchoolDate}" pattern="dd-MM-yyyy" /> </td>
<td align="center"><fmt:formatDate value="${creationDateVar.childAdmissionDate}" pattern="dd-MM-yyyy" /></td>
</tr>
</c:forEach>
</c:forEach>
</c:forEach>
</table>
</c:otherwise>
</c:choose>
</body>
</html>
所以,當我提取不從這個jsp的數據,但是從我的main()方法它完美的罰款。這意味着我的實現 - dao類運行穩定。但是當我使用這個jsp時,它提取了10次相似的數據。我想到這個標籤<c:forEach>
,這裏是一定會出現問題的。請幫我解決它。你的建議,也許我不需要<c:forEach>
標籤,有可能是不同的東西。
謝謝你的回答。你的答案毫無疑問是非常專業的,甚至很難理解。 Whan是「n立方體」?我的道路正常工作,它返回任何我需要的東西,以便我更喜歡它在控制檯中返回,但現在我需要將所有這些數據放到我的表中,使它看起來像一個更準確的用戶表。我需要遍歷它們如果我有更多的一個對象作爲dao的模型屬性返回。我發現的一個解決方案是在jsp中迭代它們,但是這是一個問題,我甚至無法正確地從dao迭代屬性。不管怎樣,謝謝你。 –
您正在運行3個嵌套循環。爲簡潔起見,我假定每個循環都在n個項目上運行。然後n * n * n迭代將發生。這就是n多維數據集時間複雜度。 DAO提取多少數據?如果jsp必須渲染大量數據,那麼最好使用分頁。下面是一個簡單的jsp分頁示例:http://theopentutorials.com/examples/java-ee/jsp/pagination-in-servlet-and-jsp/ –
麥克裏彭非常感謝您的回答。我的dao最多可以取40行,每行有9列。這是最大的。我將看看這個分頁示例,這看起來是解決問題的一種方式。 –