Question

Using an ArrayList of type Countries that is a bean class I'm getting only a blank page as output when using the following code:

<%
    ArrayList<Countries> countryList = (ArrayList<Countries>) request.getAttribute("al");
%>

<c:forEach items="${countryList}" var="item">
    <c:out value="${item.code}"></c:out>
    <c:out value="${item.name}"></c:out>
</c:forEach>
Était-ce utile?

La solution

you need not to set in request attribute again.You can use below code

<c:forEach items="${al}" var="item">
    <c:out value="${item.code}"></c:out>
    <c:out value="${item.name}"></c:out>
</c:forEach>

This way you can get rid of scriptlet also.

Hope it Helps

Autres conseils

The reason is the EL (Expression language) can't find any variable named countryList in any valid scope. The variable declared in the scriptlet is not visible to the EL so you must add it to a valid scope for example the request so:

<%
    ArrayList<Countries> countryList = (ArrayList<Countries>) request.getAttribute("al");
    request.setAttribute("countryList", countryList);
%>

<c:forEach items="${countryList}" var="item">
    <c:out value="${item.code}"></c:out>
    <c:out value="${item.name}"></c:out>
</c:forEach>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top