It's not a secret anymore!*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes getting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "getting "No tag "forEach" defined in tag library imported with prefix "c" "" Watch "getting "No tag "forEach" defined in tag library imported with prefix "c" "" New topic
Author

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

Suchitra Bhat
Ranch Hand

Joined: Dec 30, 2005
Posts: 62
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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 ]

[My Blog]
All roads lead to JavaRanch
Suchitra Bhat
Ranch Hand

Joined: Dec 30, 2005
Posts: 62
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

Joined: Dec 06, 2004
Posts: 116
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.


Balasubramani SD,<br />SCJP 1.4,SCWCD 1.4,SCJP 5.0<br /><a href="http://sd.balasubramani.googlepages.com" target="_blank" rel="nofollow">www.sd.balasubramani.googlepages.com</a>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Dec 30, 2005
Posts: 62
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

Joined: Aug 12, 2005
Posts: 11
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getting "No tag "forEach" defined in tag library imported with prefix "c" "
 
Similar Threads
JSP EL not working
Tag Library Decriptor Problem
Problems making Struts/JSTL 1.2 site work with JSTL 2.0
Error while Coding TagLibs
Versions of JSTL and EL on a legacy project