0

when i want to display the list in my jsp page.i'm getting this error

my foreach loop to display the list:

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

my controller:

@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;
}

when i completely remove the foreach loop the jsp will display without any exception.

Exception: 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) root cause:

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)
1
  • Are you sure patientService.getAllConsultant() is not null? If null return new ArrayList<>(0) in patientService.getAllConsultant(). Or better an immmutable List. Commented Mar 22, 2013 at 12:58

3 Answers 3

3

The ${consultantsList} here is

${consultantsList.name}

is a List, however i am attempting to access it as if it is a single User. This is not valid. In EL, a List can only be accessed with an integer index, indicating the position of the list item you'd like to access, like so the below statement gives me the names

${consultant[1]}

Sign up to request clarification or add additional context in comments.

Comments

0

Your <c:out> tag isn't written properly, and as a result isn't being closed. You have this:

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

It should look like this:

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

Comments

0

wrap the for each with an if condition checking the size and null check for the consultantsList object. Please paste the exception coming.

3 Comments

a bit more stack trace after this line javax.servlet.http.HttpServlet.service(HttpServlet.java:803) root cause
i may be going out of the way but can you check the version of JSP tag library and update it with the latest version..just try
thanx for you time..i got the answer The ${consultantsList} here is ${consultantsList.name} is a List<Consultant>, however i am attempting to access it as if it is a single User. This is not valid. In EL, a List can only be accessed with an integer index, indicating the position of the list item you'd like to access, like so the below statement gives me the names ${consultant[1]}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.