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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top