Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

What is wrong in th code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am new to Web component . Can any body tell what is wrong in my code. When i execute it i get blank page no error.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%
String [] myList = {"gadar","lagaan","DCH","ghayal"};
%>


<c:forEach var="listOfMovie" items="${myList}">
<tr>
<td>
${listOfMovie}
</td>
</tr>
</c:forEach>
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this :

<% String [ ] myList = {"gadar","lagaan","DCH","ghayal"};
request.setAttribute("myList", myList);
%>


value of items attribute in c:forEach is an attribute set by the request object.

this shud work fien....
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
kaju:

The problem with your code is mainly with the attribute items in the <c:forEach>. You are using the EL expression ${myList}. This means that an attribute should exist in one of the scopes (page, request, session or application).

In your code you only declared a local variable String[] called "myList". Thus, you must set the attribute in any one of the scopes.
pageContext.setAttribute("myList", myList)
or
request.setAttribute("myList", myList)
or
session.setAttribute("myList", myList)
or
application.setAttribute("myList", myList)
or any one of the following:
pageContext.setAttribute("myList", myList, pageContext.REQUEST_SCOPE);
pageContext.setAttribute("myList", myList, pageContext.SESSION_SCOPE);
pageContext.setAttribute("myList", myList, pageContext.APPLICATION_SCOPE);

hth
 
reply
    Bookmark Topic Watch Topic
  • New Topic