Question

pleas check the code below:

<%
    List list = new ArrayList();
    list.add("susheel");
    list.add("singh");
%>

<c:forEach items="${list}"  var="list1">
    <c:out value="${list1}"/>
</c:forEach>

This is the code I am trying to execute but unable to get output. Please help me find the problem thanks.

Était-ce utile?

La solution

The JSP EL doesn't use local scriptlet variables. It uses scoped attributes. You code would work if the scriptlet did:

request.setAttribute("list", list);

But you should never use scriptlets. The Java code should be in a controller written as a Java class. And the Java code should use generic types, not raw types: List<String> ad not List.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top