| Author |
JSTL not working
|
Tom Henricksen
Ranch Hand
Joined: Mar 23, 2004
Posts: 135
|
|
This is a JSP from an example for Spring Developer's notebook. <%@ page import="com.springbook.*"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> <html> <head> <title> <c : out value="${rentaBike.storeName}" /> </title> </head> <body> <h1><c : out value="${rentaBike.storeName}" /></h1> Edit a bike: <br/> <c:forEach items="${rentaBike.bikes}" var="bike"> <a href="editBike.bikes?bikeSerialNo=<c : out value="${bike.serialNo}" />"><c : out value="${bike.manufacturer}" /> - <c : out value="${bike.model}"/><br/> </c:forEach> <br/><br/> <a href="newBike.bikes">Add a new bike</a> </body> </html> When I deploy this and run it I get this ${rentaBike.storeName} for the header. All the c : out's do this. I have the c.tld and the two(jstl.jar and standard.jar) jars deployed with the webapp. Any suggestions? Thanks in advance, Tom [ October 25, 2005: Message edited by: Tom Henricksen ] [ October 25, 2005: Message edited by: Tom Henricksen ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
What is your container?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Tom Henricksen
Ranch Hand
Joined: Mar 23, 2004
Posts: 135
|
|
I am using Tomcat 5.0.28. If I run this page: <%@ page import="com.springbook.*" %> <% RentABike store = new ArrayListRentABike("Bruce's bikes"); System.out.println("Just called ArrayListRentABike"); %> <html> <head> <title> <%= store.getStoreName() %> </title> </head> <body> <h1><%= store.getStoreName() %></h1> <table border="1" cellspacing="2" cellpadding="2"> <tr style="font-weight: bold;"> <td>Manufacturer</td><td>Model</td><td>Status</td> </tr> <% for(int i=0;i<store.getBikes().size();i++) { %> <% Bike bike = (Bike)store.getBikes().get(i); %> <tr> <td><%= bike.getManufacturer() %></td> <td><%= bike.getModel() %></td> <td><%= bike.getStatus() %></td> </tr> <% } %> </table> </body> </html> It seems to work okay. That is why I am guessing the problem is with JSTL. Who knows... Thanks, Tom
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
The URI you are using for the JSTL is a JSTL 1.0 URI. With Tomcat 5, which is a JSP 2.0 container you need to be using JSTL 1.1. There is a JSP FAQ entry with links to the JSTL 1.1 downloads.
|
 |
Don Stadler
Ranch Hand
Joined: Feb 10, 2004
Posts: 451
|
|
I ran into this puppy also. As Bear said you need the new jars and tld files from Jakarta, but that isn't quite enough. You have to hack web.xml and the include.jsp from the book examples. --------------- web.xml --------------------------------- <?xml version="1.0" encoding="ISO-8859-1" ?> <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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Test web app </display-name> <taglib> <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri> <taglib-location>/WEB-INF/lib/c.tld</taglib-location> </taglib> <servlet> <servlet-name>rentaBikeApp</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>rentaBikeApp</servlet-name> <url-pattern>*.bikes</url-pattern> </servlet-mapping> </web-app> --------------- end web.xml ----------------------------- --------------- include.jsp ----------------------------- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> --------------- end include.jsp -----------------------------
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
There is no need to place any declaration in the web.xml. P.S. Please resist the urge to ressurect zombies. This thread is close to a year old.
|
 |
Joel Thompson
Greenhorn
Joined: Oct 04, 2006
Posts: 15
|
|
Hi Bear, Hopefully pointing out something useful for folks with the web.xml. (As I just ran into this problem recently and was rather frustrating). I did notice that if you didn't have anything specified in the <web-app>, then you'd get the behavior that was originally posted, ie the el expressions don't evaluate. No values show up. It is critical to have something like: <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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> Depending on the version that you are using. Best to check out the "samples" that usually come with the container to see the exact spec on this. Thanks!
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1005
|
|
You know what? Thats a really useful bit of information. I'm sure it'll help someone in the future. It should be in the JSP FAQ Maybe put it under a heading something like Setup JSTL or how about ServletsWebXml Hold on a sec...
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
Joel, don't get me wrong -- we do appreciate your trying to help. It's just that digging up old posts is seldom truly heplful. My mention of the web.xml, is that no taglib declaration need be made in the deployment descriptor if the jar files are correcetly placed. You are correct in that the web app must be declared as servlets 2.4, but as Stefan pointed out, that's already covered in the JSP FAQ. [ October 10, 2006: Message edited by: Bear Bibeault ]
|
 |
Joel Thompson
Greenhorn
Joined: Oct 04, 2006
Posts: 15
|
|
Stefan - yes, I do detect the sarcasm... and that's ok...(the old RTFM). However, I'd like to point out something that I have observed (I am new to javaranch...mind you, so bare with me, as I am not accustum to such good talent answering questions on the forum as moderators/sheriff..etc. which is an outstanding concept!). FAQ's are helpful, yet even the FAQ in this case doesn't address the cause and affect of the original problem; and folks would be more inclined to "search" the forum (I'd suspect) than to look at the FAQ right away. You see, the FAQ doesn't state that if you don't put the right <web-app...>, you'll get unexpected behaviour like only the expression and not the values showing up. Just my two cents. Thanks again for your help.
|
 |
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1348
|
|
ElOrJstlNotWorkingAsExpected
Originally posted by Joel Thompson: FAQ's are helpful, yet even the FAQ in this case doesn't address the cause and affect of the original problem; and folks would be more inclined to "search" the forum (I'd suspect) than to look at the FAQ right away. You see, the FAQ doesn't state that if you don't put the right <web-app...>, you'll get unexpected behaviour like only the expression and not the values showing up.
[ October 11, 2006: Message edited by: Carol Enderlin ]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56192
|
|
|
As a result of Joel's note, I have also added a little blurb to ServletsWebXml noting that the 2.4 XML Schema is necessary to enable the JSP 2.0 EL.
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1005
|
|
Yeah, I guess my tolerance was a little low yesterday. At least we know your sarcasm meter is working fine. If you do a forum search, you will find that this type of question gets asked (and answered) every day or so. So much for forum search/FAQ. Maybe thats because of lazy posters, maybe the FAQ isn't clear enough, or linked well enough (though I would think the former more likely) Just out of interest how did you solve your original problem?
|
 |
Joel Thompson
Greenhorn
Joined: Oct 04, 2006
Posts: 15
|
|
|
I'm not the original poster, but my problem and I suspect his was solved by putting the proper <web-app> attributes in place.
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1005
|
|
I did pick up the fact you were not the original poster (coming back to a question after a year is rather uncommon) You referred to being frustrated with this issue yourself recently. I was wondering how/where you got the solution that then prompted you to post it here - from this site? elsewhere on the internet? reading docs? trial and error?
|
 |
Joel Thompson
Greenhorn
Joined: Oct 04, 2006
Posts: 15
|
|
|
I found the solution from trial and error.
|
 |
 |
|
|
subject: JSTL not working
|
|
|