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>
Was it helpful?

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

OTHER TIPS

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top