0

servlet code :

     List<Uscensuspopulationdata> ls = query.list();

      request.getSession().setAttribute("out", ls);
      response.sendRedirect("fulldata.jsp");

JSP code: //out has represents the entire list. so out[0].name works. //but i dont know how to iterate to display all the records

       ${out[0].name}

I want to display something like this: ${out[i].name} inside a loop so that i can get all the names from the list

Reimeus
  • 158,255
  • 15
  • 216
  • 276
user1736333
  • 183
  • 2
  • 3
  • 11
  • Put your mouse on the `[jstl]` tag below the question until a black box pops up. Click therein the *info* link. Take your time to read it carefully. – BalusC Oct 17 '12 at 02:27

3 Answers3

1

You would use forEach:

<c:forEach items="${out}" var="theItem">
  <c:out value="${theItem.name}" />
</c:forEach>
prodigitalson
  • 60,050
  • 10
  • 100
  • 114
0

Since you've posted it on the session, try explicitly declaring the list in the session scope via ${sessionScope...

<c:forEach items="${sessionScope.ls}" var="e">      
    ${e.name} <br> 
</c:forEach> 
Herupkhart
  • 499
  • 4
  • 23
0

Didn't you forget to add declaration <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

Alex
  • 11,451
  • 6
  • 37
  • 52