java.lang.NumberFormatException:对于输入字符串:“name”

时间:2013-03-22 12:02:18

标签: java spring hibernate

当我想在我的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)

3 个答案:

答案 0 :(得分:2)

$ {consultantsList}这里是

  

$ {consultantsList.name}

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

  

$ {顾问[1]}

答案 1 :(得分:0)

您的<c:out>代码未正确写入,因此未被关闭。你有这个:

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

它应该是这样的:

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

答案 2 :(得分:0)

用if条件包装for each,检查的大小和null检查所有的authorsList对象。请粘贴异常。