• 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

problem iterating over header in JSP with JSTL

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally got the JSTL to work out and I am going through some sample things in a beginner JSP book I have. They have one code sample:



The loop is working. I changed it to iterate a certain number of times just fine, but as it is I only get one row of output and it outputs the text "${entry.key} - ${entry.value}" and does not seem to actually get any header info and cycle through all of it.

I have searched around trying to figure out if this is a bad method of getting header info, but I can only find commands for getting a specific part of the header like:


Can anyone fill me in on what I am missing to get the sample book code to work?

Thanks
[ September 01, 2004: Message edited by: Rick Harding ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works just fine for me.

You gave nothing in the way of environmental information. I assume you are running on a JSP 2.0 container like Tomcat 5? And that you have declared the web app to be a Servlet 2.4 web application in the web.xml file?

The fact that the EL expressions are not being translated is suspect. What happens when you put something like:



in your page? Do you get "7", or "${3 + 4}" emitted?
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry, forgot some info.

Yes I am running Tomcat 5.0.28 and my web.xml file is just enough to get my JSTL to work:


<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">

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

</web-app>



Putting ${3+7} does not output 7, just that exact text so it seems I have something wrong that does not parse properly? Any ideas?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, the problem has nothing to do with the JSTL. Tomcat has not turned on EL expressions on your page (as evidenced by the "3 + 4 check").

Your web-app delcaration looks a little sparse; try this:



which works well for me, and then try the "3 + 4" check again.
[ September 01, 2004: Message edited by: Bear Bibeault ]
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I read some more up on the web.xml file and I don't see how what I am doing comes into being a servlet and must be defined in the web.xml so. I just have a single index.jsp file that I am playing with. The full content is this:



I am sorry for being so new to this stuff, man you have to have a LOT more environmental stuff to get JSP working than PHP.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Btw, the taglib declaration in your web.xml is not necessary -- Tomcat will find the tld in the standard.jar file automatically -- and is wrong (specifies the URI for version 1.0 of the JSTL). The URI you are using on your page contains the correct (JSTL 1.1) URI.

P.S. You do have the JSTL 1.1 jars, right?
[ September 01, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am sorry for being so new to this stuff, man you have to have a LOT more environmental stuff to get JSP working than PHP.



No prob. Eveyone is a beginner at one point.

And yes, there's a lot of goo to set up -- but it's worth it for the power you get.
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Btw, the taglib declaration in your web.xml is not necessary -- Tomcat will find the tld in the standard.jar file automatically -- and is wrong (specifies the URI for version 1.0 of the JSTL). The URI you are using on your page contains the correct (JSTL 1.1) URI.


Thanks, I was following some instructions I found. I removed it.

Ok, I updated the web-app declaration and still not replacing of EL expressions. Everything I read and search for seems to imply that it is something that should be on by default as long as it is specified as version 2.4 in the web.xml file.

Anything else I am missing?

P.S. You do have the JSTL 1.1 jars, right?


I am using jakarta-taglibs-standard-current.zip from today. They are supposed to be 1.1 supporting from what I read.

[ September 01, 2004: Message edited by: Rick Harding ]
[ September 01, 2004: Message edited by: Rick Harding ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm, sorry to say that I'm rather stumped at this point. Setting up the web.xml using the declaration as above has always been enough to turn on the EL for all the web apps I work on (about a dozen or so).

Hope this doesn't give you a bad taste for JSP... there are a lot of setup steps, but it's usually pretty straight-forward.

We need more clues...

First the simple stuff.

Where are you setting this up? What is the folder structure? Are you creating your own context or piggybacking on Tomcat examples? Is the web.xml in the right place (WEB-INF)?

At this point, I suspect the web.xml is not even being read and that it may be as simple as not having your web app layout set up to Tomcat's liking.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an exercise to try.

Create this folder:



(btw, $CATALINA_HOME is where you installed tomcat)

Put a file named index.jsp in that folder that contains:



Create folder $CATALINA_HOME/webapps/simple/WEB-INF

Create a web.xml in that folder containing:



This is pretty much the absolute minimal web application.

Restart Tomcat and hit http://localhost:8080/simple

What happens?
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok that worked.

I am using eclipse and it seems that somehow by using eclipse it must not be reading the web.xml file. Sorry to bug you with something like this. I guess the poster in my other thread was right, I should probably start without eclipse. I am just used to having a nice code comletion IDE when coding.

Thanks for the help!
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, glad it's working.

Other thread? In the future please don't cross-post. I had no idea another conversation was going on, and there could be redundancy that wastes people's time.

Have fun with JSP!
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naw, not a cross post. I know better than that. I had a different problem earlier in servlet forum that someone suggested I wait on using eclipse.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, cool. Well, any other issues you have with JSP, you know where we are!
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to come late to this conversation.

What you discovered is the "compatibility mode" that you get if you don't have a Servlet 2.4 (JSP 2.0) style web.xml file. In this mode, container EL support is disabled.

I notice that the JSTL forEach tag still evaluated its expression, which means that you're using the JSP 1.2 version of JSTL 1.0 with EL support in the tag library. In a JSP 2.0 container, you don't need this; it is just overhead. Instead of using http://java.sun.com/jstl/core, use <a href="http://java.sun.com/jstl/core<b rel="nofollow">_rt</b>." target="_blank">http://java.sun.com/jstl/core_rt. Or, alternatively, use a JSTL 1.1 implementation.

The best way to get things working is, as indicated above, to have a proper web.xml file. But it might be useful to know that you can also enable the EL on a JSP-by-JSP basis by including the following at the top of your page:

<%@page isELIgnored="false"%>

- Peter
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I am a bit confused. I THOUGHT that the jakarta-taglibs were 1.1. Now I tried to change the taglib to core_rt and got errors. The placing of the <%@page isELIgnored="false"%> in the file helped get the EL expressions to work in Eclipse so that is cool.

So can you explain how with Tomcat 5.0.28 (which I thought was a JSP 2.0 container) and the jakarta taglibs are somehow acting like a JSP 1.2 with 1.0 of the libs? Is there some kind of fallback mode or something I might be running into?
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick Harding:
Ok, I am a bit confused. I THOUGHT that the jakarta-taglibs were 1.1. Now I tried to change the taglib to core_rt and got errors.

Strange. What errors?

So can you explain how with Tomcat 5.0.28 (which I thought was a JSP 2.0 container) and the jakarta taglibs are somehow acting like a JSP 1.2 with 1.0 of the libs? Is there some kind of fallback mode or something I might be running into?

You were running the JSP container in JSP 1.2 compatibility mode because you didn't have a Servlet 2.4 (JSP 2.0) web.xml file. The taglibs you use clearly have EL support built in - in JSP 2.0, this EL support is the responsibility of the container itself.

I just checked and jakarta-taglibs-standard-1.1.1 (the latest), which ostensibly is a JSTL 1.1 implementation for JSP 2.0 and above, actually appears to contain full support for JSP 1.2 containers including an EL evaluation engine. That's what you were probably using: you have the right taglib version, but you were using the 1.2 compatible tags.

To use the JSP 2.0 flavour of the core tags, use the following taglib URI: http://java.sun.com/jsp/jstl/core . Note the "jsp" path Actually this is exactly as stated in the JSTL 1.1m1 spec; my oversight, apologies.

- Peter
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the core-rt tld is for JSTL 1.0. Be sure to use the right URI (the last one Peter gave in hist previous message) to use the JSTL 1.1 tld.

You have the EL evaluating correctly on your pages now, right?
 
Rick Harding
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yep, as long as I use the uri without the _rt on it I am fine.

Thanks for the help and helping me understand a bit more about how all this works.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic