• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

What is wrong in th code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic