Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is wrong in th code

 
kaju Tiwari
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>
 
Rajesh Vijaya
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....
 
M Jairam
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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!