Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

JSTL newbie question

Thread view: 
ola.mattsson@gmail.com - 25 Oct 2006 23:21 GMT
Hi, I've just started working with taglibraries in jsp pages but I
can't get it to work...
I have a very simple "helloWorld.jsp" page where I try to list all
headers in the request.
Here is the complete jsp page code:

<%@ page language="java" import="java.util.*"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%
Enumeration headerNames =  request.getHeaderNames();
Map<String, String> headers = new HashMap<String, String>();
while(headerNames != null && headerNames.hasMoreElements()){
    String s = (String)headerNames.nextElement();
    headers.put(s, (String)request.getHeader(s));
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
   <title>My JSP 'helloWorld.jsp' starting page</title>
 </head>
 <body>
   This is my JSP page. <br>
   Welcome to the world of JSP.<br>
   <c:forEach var="entry" items="${headers}">
   ${entry.key } = ${entry.value }
   </c:forEach>
 </body>
</html>

When I access this page in a browser I get the Internal Server error
message:
"org.apache.jasper.JasperException: /helloWorld.jsp(20,4) According to
TLD or attribute directive in tag file, attribute items does not accept
any expressions"

As I understand it I can't use the EL expression ${headers} to set the
value for the items attribute in the <c:forEach ></c:forEach> tag.
But in every "tutorial" I've seen (not that I've found any *good*
tutorial) on the subject, you use an EL expression to set the items
attribute, so what is wrong here?

I'm running this on a Tomcat 5.5.20 and the webapp is deployed by the
MyEclipse J2EE development plugin for Eclipse.

So, can you either tell me about a good taglibs tutorial or if you know
what the cause for this problem is (besides the problem between the
chair and the keyboard of course) and how to solve it?
Manish Pandit - 25 Oct 2006 23:55 GMT
After the while loop, put pageContext.setAttribute("headers",headers);
and see if that works.

-cheers,
Manish
grasp06110@yahoo.com - 25 Oct 2006 23:59 GMT
Don't know of a good tutorial.  If I recall correctly there is a
chapter in Marty Hall's Core Servlets and JSPs (vol 2?) thats prety
good (I don't have it here so I can't check).

What does your web.xml file look like.  You should have something like
the following in it:

   <taglib>
     <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
     <taglib-location>/WEB-INF/fmt.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
     <taglib-location>/WEB-INF/c.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
     <taglib-location>/WEB-INF/sql.tld</taglib-location>
   </taglib>

   <taglib>
     <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
     <taglib-location>/WEB-INF/x.tld</taglib-location>
   </taglib>

You probably also want to put this at the top of the page.

 <%@ page isELIgnored="false" %>  

Good Luck!
grasp06110@yahoo.com - 26 Oct 2006 00:03 GMT
What happens when you try something like <c:out value="${entry.key}" />?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.