• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting "No tag "forEach" defined in tag library imported with prefix "c" "

 
Suchitra Bhat
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying with a simple JSP which has <c:forEach> tag.
My tld looks like this

<taglib xmlns = "http://java.sun.com/xml/ns/j2ee"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version ="2.0">

<tlib-version>1.2</tlib-version>
<uri>http:http://java.sun.com//jsp/jstl/core</uri>
</taglib>

and i have placed jstl.jar and standard.jar in WEB-INF/lib folder in my WebApp.

I am getting the exception No tag "forEach" defined in tag library imported with prefix "c" "

Please help me how do i correct this and also y am i getting this ??

Thanks in Advance,
Suchitra
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that the URI is correct ?
<uri>http:http://java.sun.com//jsp/jstl/core</uri>

Please check this first.

Another thing.
What do you mean by "my TLD" ?
Do you mean that you have made a TLD file to use JSTL ?
This doesn't make sense, so could you explain what you are trying to do ?
Thanks.
[ January 23, 2006: Message edited by: Satou kurinosuke ]
 
Suchitra Bhat
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what i am trying to do

1) My JSP looks some thing like this

<%@ taglib prefix = "c" uri = "http://java.sun.com/products/jsp/jstl/" %>
<html>
<body>
<% Sting [] testCforEach = {"A","B","c","D"}; %>
<table>
<c:forEach var = "item" items = "${testCforEach}" >
<tr>
<td>${var}</td>
</tr>
</c:forEach>
</body>
</html>

I have kept this jsp in one of the projects folders inside webapp folder.
This projects folder has a WEB-INF and lib folder.

Web.xml looks like this

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
</web-app>

No other tags in web.xml

I have also created a file with .tld extension and kept it in WEB-INF itself
I have named the tld file has MyTest.tld and it looks like this

<?xml version="1.0" encoding="ISO-8859-1" ?>

<taglib xmlns = "http://java.sun.com/xml/ns/j2ee"
xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version ="2.0">

<tlib-version>1.2</tlib-version>
<uri>http://java.sun.com/products/jsp/jstl/</uri>
</taglib>


I have put the jar files jstl.jar and standard.jar in WEB-INF /lib folder.
I got these two jar files when i downloaded tomacat 5.0.28

First i tried without writing a tld and just keeping the jar files in lib folder. That didnt work and then i wrote a tld.
If using tld for jstl is not correct, pls let me know how do i use jstl in my jsp's.

Thanks in Advance,
Suchitra
 
Balasubramani Dharmalingam
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suchithra,
Dont write any tlds for JSTL tags.Just put jstl.jar and standard.jar inside WEB-INF/lib folder then use forEach tag as follows,



If u have any problem with this code let me know.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Balasubramani said, you should not create the TLD. There are already in the JAR files.

So remove MyTest.tld and try this in your JSP file:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
Suchitra Bhat
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Thanks a lot for the help.

Now i have removed the tld file and have just JSP and included the jar files in WEB-INF/lib in my WebApp folder.

But now i am facing
org.apache.jasper.JasperException: /testCforEach.jsp(6,2) According to TLD or attribute directive in tag file, attribute items does not accept any expressions

Any help would be appreciated.
thanks in advance,
Suchitra
 
Jay Tse
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that when you are print it out inside the table, you need to use
${item} instead of ${var}, since item is the name of the variable you have declared (with var="item") to hold the value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic