0

Hi I am trying to print the list of strings stored in ArrayList object using JSTL, here is my jsp page:

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>    
<%         
    List<String> al = new ArrayList<String>();        
    al.add("testing1");        
    al.add("testing2");        
    al.add("testing3");
    al.add("testing4");        
    al.add("testing5");        
    System.out.println("hello"+ al);           
%>
    <c:forEach var="alla" items="${al}" >       
        <c:out value="Hello text"></c:out>        
        <c:out value="${alla}"></c:out>        
    </c:forEach>

when i see output it is not showing any thing on the browser, I have printed it using foreach it is showing the result where as in JSTL it is not printing ?

Santhosh
  • 8,181
  • 4
  • 29
  • 56
ASR
  • 3,289
  • 3
  • 37
  • 65

1 Answers1

4

jstl is used to print the objects from the session or request scopes. you did not set your List al either of those .

Try adding it to the session and then access it through jstl

HttpSession session = request.getSession();
session.setAttribute("al", al);

and use c:forEach to print it in your page.

See also

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56