File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Why list is not being printed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why list is not being printed?" Watch "Why list is not being printed?" New topic

Why list is not being printed?

Salil Dhawan
Ranch Hand

Joined: Jul 18, 2006
Posts: 55
Below is code stub which just makes a list on JSP and prints each value using forEach tag.But here its not printing the value?Can you let me know the error?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@taglib prefix="c" uri="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

List list = new ArrayList();
list.add("1"); list.add("2");
list.add("3"); list.add("4");

<c:forEach var="value" items="${list}" varStatus="status">


Salil Dhawan<br />SCJP 1.4, SCWCD 5.0, SCDJWS 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">ViewPoint</a>
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39549
"list" is not defined in a way that the EL can get at it. If you add it as an attribute it should work. Something like:

Ping & DNS - updated with new look and Ping home screen widget
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575


you are setting values into list..then you try to print it..right?

you do this in servlet..then you forward to jsp page using request.settAttribute("key",list);

then in jsp something like this:

<c:forEach var="value" item="${list}">
now it will work...(please import jstl properties )

thanks & regards,
jQuery in Action, 2nd edition
subject: Why list is not being printed?
Similar Threads
JSTL forEach
passing different parameters to different frames in Frameset jsp
How to retain formatting when passing a String to a JSP
Iterating through local List using JSTL
Hibernate and JSP