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.

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top