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>
有帮助吗?

解决方案

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

其他提示

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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top