• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tutorial For <c:forEach> JSTL That Should Work

 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I did, and it doesn't work (as in, look at the images at the end to see exactly what it looks like). It's a 10 minute job if you happen to have the same Eclipse version I'm using and Tomcat 6 already installed. I'm probably just being an idiot again, but dang if I can see it.

1. Helios new dynamic web project version 2.5, "SmallWebProject"
2. Java Build Path > Add External Jars > (tomcat6 install)\lib\servlet-api.jar
3. Java Build Path > Add External Jars > (tomcat6 install)\webapps\examples\WEB-INF\lib\jstl.jar
4. new servlet com.drs.TestElServlet.java


5. new jsp file (xhtml, xml, syntax) WebContent/ThingDisplay.jsp

6. add [xmlns:c="http://java.sun.com/jsp/jstl/core"] to the [<jsp:root...>]

7. between body tags, add


(presuming you have a Tomcat 6 server defined...sorry if you don't, not covering here)

8. Double click a Tomcat 6 server, modules tab, add web module, select project

9. Start the server

10. Visit http://localhost/SmallWebProject/TestElServlet with your browser (in my case localhost:9980, etc)

And I see this (unexpected...remember, we put "Thing 1", "Thing 2", "Thing 3"):


And in view source, I see this (hmmm, it "sees" the String[] object);


11. What say you?

--Dale--
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSTL is not being evaluated. Do you have the JSTL enabled for your project? And why are you using JSP documents (the XML format of JSP) instead of JSP pages? No one does that. It's not meant for humans but for machines.

It may be as simple as the fact that you have whitespace before the <?xml> declaration, but I urge you to revisit the decision to use JSP XML documents rather than JSP pages. You will run into pitfall after pitfall.
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:The JSTL is not being evaluated. Do you have the JSTL enabled for your project?
Thank you kind sir, for the analysis. As far as I know, yes, jstl is enabled. Before adding the jstl jar file, there was a syntax error, and after adding, it went away. So that's one bit of enabling. The top of the web.xml file looks right, as compared to ServletsWebXml, for Tomcat 6, which is another bit of enabling. I'm not sure how much more is required.

Bear Bibeault wrote:And why are you using JSP documents (the XML format of JSP) instead of JSP pages?
No reason except it looked the most complicated (so must be better ). I shan't do that any more.

So I tried this again, with a few differences. Regular JSP pages. Used the jstl jars for Tomcat 6 from JstlTagLibDefinitions instead of referencing the ones out of the Tomcat 6 directory.

1. Helios new dynamic web project version 2.5, "SWP2" (same)
2. Java Build Path > Add External Jars > (tomcat6 install)\lib\servlet-api.jar
3. Java Build Path > Add External Jars > (tomcat6 install)\webapps\examples\WEB-INF\lib\jstl.jar

2. Download jstl-api-1.2.jar and jstl-impl-1.2.jar from http://jstl.java.net/download.html and put in project.
3. Java Build Path > Add Jars > jstl-api-1.2.jar, jstl-impl-1.2.jar
4. new servlet com.drs.TestElServlet.java (same)
5. new jsp file (xhtml, xml, syntax) WebContent/ThingDisplay.jsp
5. new jsp file (html) WebContent/ThingDisplay.jsp
6. add [xmlns:c="http://java.sun.com/jsp/jstl/core"] to the [<jsp:root...>]
6. add "<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>" after the java language page directive.
7. between body tags, add c:forEach (same)
8. Double click a Tomcat 6 server, modules tab, add web module, select project (same)
9. Start the server (same)
10. Visit http://localhost/SWP2/TestElServlet with your browser (in my case localhost:9980, etc) (same)

11. I see this error:


Maybe it's some kind of configuration issue with the server, or something. I thought it was "just supposed to work", though. I'm going to download a fresh install of Tomcat 6, and see if that helps.

--Dale--

Edit: Fresh Tomcat 6 install did the same thing.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have put the JSTL jar (or jars depending on which version and where you got them) in WEB-INF/lib, they will be automatically found.

There is no further configuration needed.

Here's a tip: "more complicated" never means "better".
 
Dale Seng
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:If you have put the JSTL jar (or jars depending on which version and where you got them) in WEB-INF/lib, they will be automatically found.
That was it. I knew I was being an idiot. I've been away from this too long!

Here are the corrected steps:

2. Download jstl-api-1.2.jar and jstl-impl-1.2.jar from http://jstl.java.net/download.html and put in project and put into WEB-INF/lib.
3. Java Build Path > Add Jars > jstl-api-1.2.jar, jstl-impl-1.2.jar

In "2." I just dropped the jars into the top of the project, and in "3." I made it so the build could "see" the jars. And in "3b." (which I didn't elaborate upon), I also had the jars deployed with the project (build path order and export tab). But they landed in the wrong spot.

Thanks for your help and patience. And I get it about the complexity

--Dale--
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!