0

我有一个这样的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>标签,可能有不同的东西。

4

1 回答 1

0

如果您使用 c:forEach 编写了太多内容,那么这将需要时间。从您的示例中,我发现复杂度为n cube。基本上在服务器端生成html,并在服务器发送后在客户端呈现。例如,如果您在页面中写入1000 行,则会在缓冲区中生成一个巨大的 html 页面。如果缓冲区大小很大,则刷新它需要时间。

最重要的一点是响应时间取决于您写入的数据量

因此,为了提高性能,您可以执行以下操作

  • 尽量避免n 立方复杂度。做,在DAO中做一些事情,以便在 jsp 页面中您可以编写n阶复杂度。
  • 不要一次渲染全部数据。而是渲染部分数据并使用分页来获取更多数据。
于 2013-06-26T16:16:28.083 回答