2013-06-26 30 views
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>標籤,有可能是不同的東西。

回答

0

如果使用c:forEach編寫太多的內容,則需要時間。從你的例子中我發現複雜性是n立方體。基本上在服務器端生成html,並在服務器發送它後在客戶端呈現。例如,如果您在頁面中寫入1000行,則會在緩衝區上生成一個巨大的html頁面。如果緩衝區大小很大,則需要花費時間來刷新它。

最重要的一點是,響應時間取決於你有多少數據寫入

因此,對於性能的提高,你可以做以下

  • 儘量避免ñ立方體複雜性。在DAO中做一些事情,以便在jsp頁面上您可以訂購n複雜性。
  • 請勿一次呈現完整數據。而是渲染部分數據並使用分頁獲取更多。
+0

謝謝你的回答。你的答案毫無疑問是非常專業的,甚至很難理解。 Whan是「n立方體」?我的道路正常工作,它返回任何我需要的東西,以便我更喜歡它在控制檯中返回,但現在我需要將所有這些數據放到我的表中,使它看起來像一個更準確的用戶表。我需要遍歷它們如果我有更多的一個對象作爲dao的模型屬性返回。我發現的一個解決方案是在jsp中迭代它們,但是這是一個問題,我甚至無法正確地從dao迭代屬性。不管怎樣,謝謝你。 –

+0

您正在運行3個嵌套循環。爲簡潔起見,我假定每個循環都在n個項目上運行。然後n * n * n迭代將發生。這就是n多維數據集時間複雜度。 DAO提取多少數據?如果jsp必須渲染大量數據,那麼最好使用分頁。下面是一個簡單的jsp分頁示例:http://theopentutorials.com/examples/java-ee/jsp/pagination-in-servlet-and-jsp/ –

+0

麥克裏彭非常感謝您的回答。我的dao最多可以取40行,每行有9列。這是最大的。我將看看這個分頁示例,這看起來是解決問題的一種方式。 –