• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help-standard tag c:forEach practice

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I try to practice the c:forEach. But I got errors. Can anybody tell me what's wrong with my code?

Servlet code:
****************************************
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class JstlTest extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String[] movieList={"Gone with wind","Road home", "tiger", "good bye"};
request.setAttribute("movieList", movieList);

RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request, response);
}
}
********************************************
JSP code:
----------------------------------------------------------------
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html><body>
<strong>movie list:</strong>
<br><br>

<table>
<c:forEach var="movie" item="${movieList}">
<tr>
<td>${movie} </td>
</tr>
</c:forEach>
</table>
</body></html>
-------------------------------------------------------------
I put jstl.jar in the WEB-INF/lib/

when I called servlet I got the error:

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:114)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:316)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:147)
org.apache.jasper.compiler.Parser.parseTaglibDirective

So what's wrong? Do I need tld file? How can I let this program run?

Thanks a lot.

Anna
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not complaining about the code you posted. It's complaining that the uri for the core taglib is not mapped in your web.xml file.

However, you can avoid the need to map the taglib in the web.xml by declaring a uri attribute in the directive that references your actual tld file. The appropriate uri might look something like this: /WEB-INF/c.tld
 
Anna Wang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
But I am still not very clear what should I do.
If I keep using uri="http://java.sun.com/jsp/jstl/core",then how to write web.xml file.

If I change "uri=/WEB-INF/c.tld" can anybody write the code to give me the detail how to declaring a uri attribute in the directive.

I just begin to study HFSJ. Please help me. Thank you.

web.xml file I wrote, please add something I missed:
-------------------
<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/web-app_2_4.xsd" version="2.4">

<servlet>
<servlet-name>name</servlet-name>
<servlet-class>JstlTest</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>name</servlet-name>
<url-pattern>/hello.do</url-pattern>
</servlet-mapping>

</web-app>
----------------------------------------------------------

Anna
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anna Wang:
If I change "uri=/WEB-INF/c.tld" can anybody write the code to give me the detail how to declaring a uri attribute in the directive.



What code? Just change the uri attribute. Take out the current value you set for the uri and replace it with the actual path to the tld file.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anna, If u use JSP 2.0, u no need to mention <taglib-location> using <taglib> in web.xml.
You just give the path of the tld file like "WEB-INF/c.tld"(if it exists) otherwise u can extract the c.tld from "standard.jar" or check the URI in c.tld of "standard.jar"

and also u have put the attribute name as "item", it should be items

<c:forEach var="movie" items="${movieList}">
[ June 20, 2006: Message edited by: Selvaraj Subramanian ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anna,
did you put standard.jar in your lib directory as well ?

And have a look at this FAQ :
http://faq.javaranch.com/view?JstlTagLibDefinitions
 
Anna Wang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so very much for the answer. It works now.

I made two mistake. First I did not put standard.jar in the lib, second item should be items.

Thanks again.

Anna
 
I am displeased. You are no longer allowed to read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic