0

我的控制器 Spring MVC 和 jsp 页面上的迭代有问题。当我在 jsp 页面上传递属性并尝试对其进行迭代时,它会克隆结果并在 jsp 页面上查看它(结果每次都重复)。为什么会发生以及如何预防?

我的表单jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>   

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Страница выборки</title>
</head>

<body>

<h3>Выборка</h3>

<form name="extractForm" action="result" method="GET" accept-charset="UTF-8">

<b>Дата для выборки:</b>                <input type="text" name="particularDate"> <br>

<b>Имя учреждения для выборки:</b>      <input type="text" name="nameOfInstitution"> <br>

<b>Тип учреждения для выборки:</b>      <select name="typeName" size="1">
                                        <option selected="selected" value=""></option>
                                        <option value="MBOY">МБОУ</option>
                                        <option value="MBDOY">МБДОУ</option>
                                        </select>
<br>

<input type="submit" value="Выбрать"/>
</form>

</body>

</html>

我的结果jsp页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

</head>

<body>

<table align="center" border="1">

<thead>
<tr>
<th>Наименование учреждения</th>
<th>Тип учреждения</th>
<th>Дата внесения данных</th>
<th>Режим дня</th>
<th>Режим работы</th>
<th>Очередность</th>
<th>Количество детей</th>
<th>Дети до 3-х лет</th>
<th>Дети старше 3-х лет</th>
<th>Дети пойдут в школу в ${creationDate.childGoSchoolDate}</th>
<th>Дети принятые в ${creationDate.childAdmissionDate}</th>
</tr>
</thead>    

<c:forEach items="${institutionAttrib}" var="institutionObj">
    <c:forEach items="${dateAttrib}" var="creationDate">
        <c:forEach items="${srcAttrib}" var="schRotChild">  

<tbody>
<tr>
<td>${institutionObj.nameOfInstitution}</td>
<td>${institutionObj.typeName}</td>
<td>${creationDate.particularDate} </td>
<td>${schRotChild.dayScheduale}</td>
<td>${schRotChild.workScheduale}</td>
<td>${schRotChild.rotation}</td>
<td>${schRotChild.numberOfChild}</td>
<td>${schRotChild.childUnder3YearsOld}</td>
<td>${schRotChild.childUpper3YearsOld}</td>
<td>${schRotChild.childGoToSchool}</td>
<td>${schRotChild.childAdmitted}</td>

</tr>
</tbody>

</c:forEach>
    </c:forEach>
        </c:forEach>


</table>

<jsp:include page="index.jsp"/>

</body>

</html>

还有我的 mvc 方法:

@RequestMapping(value ="/result", method=RequestMethod.GET)
        public String SecondActionPage(@RequestParam String particularDate, 
                                       @RequestParam String nameOfInstitution, 
                                       @RequestParam String typeName, 
                                       Model model) throws Exception {


                if(particularDate !="" && nameOfInstitution !="" && typeName=="") {

                    controllerSupportClass.findWithDateAndName(nameOfInstitution, particularDate, model);

                } else if(particularDate !="" && nameOfInstitution =="" && typeName !="") {

                    controllerSupportClass.findWithAddedDateAndType(typeName, particularDate, model);

                } else if(particularDate !="" && nameOfInstitution =="" && typeName==""){

                    controllerSupportClass.findWithAddedDate(particularDate, model);

                } else if(particularDate !="" && nameOfInstitution !="" && typeName !="") {

                    throw new Exception("Search by choose all parameters is not exceptable");

                } else {

                    throw new Exception("You didn't put any search parameters");

                }


            return "result";

        }

谢谢你。

4

1 回答 1

0

您是否确认在您的代码中调用的方法正在将正确的数据推送到 jsp 页面?

于 2013-06-12T11:04:56.147 回答