0

当我想在我的 jsp 页面中显示列表时,我收到了这个错误

我的 foreach 循环显示列表:

<c:forEach  var="list" items="${consultantsList}" varStatus="iter">
<c:out value="${list.name}"></c:out>
 </c:forEach>

我的控制器:

@Controller
@RequestMapping("/patient")
public class PatientController {

@Autowired
private PatientService patientService;

@RequestMapping(value="/registerPatient.htm")
public ModelAndView getRegisterPage()
{
    ModelAndView modelAndView=new ModelAndView();
    modelAndView.setViewName("register");
    List<Consultant> list=patientService.getAllConsultant();
    modelAndView.addObject("consultantsList",list);
    modelAndView.addObject("patient", new Patient());

    return modelAndView;
}

当我完全删除 foreach 循环时,jsp 将毫无例外地显示。

例外: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/jsp/i1-smhBaseLayout.jsp'. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.ja va:656) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) javax.servlet.http.HttpServlet.service(HttpServlet.java:690) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 根本原因:

org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/jsp/i1-smhBaseLayout.jsp'.
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:692)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
4

3 回答 3

3

这里的 ${consultantsList} 是

${consultantsList.name}

是一个列表,但是我试图访问它,就好像它是单个用户一样。这是无效的。在 EL 中,只能使用整数索引访问列表,指示您要访问的列表项的位置,就像下面的语句给我的名称一样

${顾问[1]}

于 2013-03-27T09:33:33.197 回答
0

您的<c:out>标签没有正确写入,因此没有被关闭。你有这个:

<c:out value="${list.name}"</c:out>

它应该如下所示:

<c:out value="${list.name}"/>
于 2013-03-22T12:04:25.260 回答
0

用 if 条件包装 for each,检查 advisorsList 对象的大小和空值检查。请粘贴即将到来的异常。

于 2013-03-22T12:28:29.360 回答