문제

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