JSTL newbie question

O

ola.mattsson

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?
 
M

Manish Pandit

After the while loop, put pageContext.setAttribute("headers",headers);
and see if that works.

-cheers,
Manish
 
G

grasp06110

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JSTL Question 10
JSTL database access 0
JSTL attempt in JSP 5
JSTL question 0
JSTL forEach 7
View page without JSTL 2
JSTL on Tomcat 5.0 0
About as basic "Newbie-Question" that you can get. 3

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top