Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
I am a man of mystery. Mostly because of this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic