Apache Jakarta Taglibs Frequently Asked Questions
Contents
- I think EL is not working? What might be wrong?
- There seem to be more than one sets of JSTL URIs, which ones do I use?
- I want to migrate from JSTL 1.0 to JSTL 1.1, what changes do I need to make?
- Using string() on a complex expression in an xml tag is returning an empty string. What's up?
- The Standard Taglib depends on Xalan. Why?
- The order of columns coming back in my SQL query does not match the order returned by the specification. Why?
- I am getting an exception - "An error occurred while evaluating custom action attribute ...". Why?
- The out tag is not handling my paramater named 'param'. Why not?
- My XML tag is resulting in "Content is not in prolog" - why?
- The last() and position() functions are not working within x:forEach - why?
- When trying to serialize XML using the Xerces (2.3.0) version that ships with JSTL 1.0.5 with JDK 1.3.1.07 I get an InvocationTargetException
I think EL is not working? What might be wrong?
- Make sure you are using a servlet 2.4 specification 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"> <!-- web.xml content --> </web-app>
Then, make sure you are using a servlet container that implements the servlet 2.4 specification [For Tomcat this is version 5.0.x and up]
There seem to be more than one sets of JSTL URIs, which ones do I use?
To support backwards compatibility, JSTL 1.1 introduced new URIs that must be specified to use the new capabilities offered in JSTL 1.1. Depending on which version of JSTL you are using, you should use the appropriate URIs.
- For JSTL 1.0, use the http: //java.sun.com/jstl/* URIs
- For JSTL 1.1, use the http: //java.sun.com/jsp/jstl/* URIs
More details are in Appendix A of the JSTL 1.1 Specification Maintenance Release, which can be downloaded from http://java.sun.com/products/jsp/jstl/
I want to migrate from JSTL 1.0 to JSTL 1.1, what changes do I need to make?
The changes required may be two-fold, related to the container as well as the web application(s) that use JSTL 1.0
- JSTL 1.0 requires a JSP container that supports the Java Servlet 2.3 and Java Server Pages 1.2 specifications (examples are Tomcat 4.x or Websphere 5.x). JSTL 1.1 requires a JSP container that supports the Java Servlet 2.4 and Java Server Pages 2.0 specifications (examples are Tomcat 5.x or Websphere 6.x). So, you must upgrade the container, if needed.
Then download the JSTL 1.1 Specification Maintenance Release from http://java.sun.com/products/jsp/jstl/ and read Appendix A (Compatibility & Migration), specifically A.2 deals which JSTL 1.0 to JSTL 1.1 migration. Make changes to your web application(s) accordingly.
Using string() on a complex expression in an xml tag is returning an empty string. What's up?
This was reported by Yuriy Yatsyk in #33032 and appears to be due to some oddity in the way the Standard Taglib uses Xalan. The work around is to split your code up so that string() is applied to a simple expression.
Using Yuriy's example change:
<x:set var="navigationPath"
select="string($content/content/pages/page/url[text() = $contentUrl]/../navigation-path)"
scope="request"/>to:
<x:set var="navigationPath"
select="$content/content/pages/page/url[text() = $contentUrl]/../navigation-path"
scope="request"/>
<x:set var="navigationPath" select="string($navigationPath)" scope="request"/>
The Standard Taglib depends on Xalan. Why?
The original source was coded against Xalan packages and not the XSL specification. It's unlikely that this will be changing any time soon, so you will need to include Xalan with your web applications. See #30050 to see if any developments occur with this issue.
The order of columns coming back in my SQL query does not match the order returned by the specification. Why?
The underlying code for sql:query uses a TreeMap to hold the row data. Unfortunately the specification limits us and we can't change this to a SortedMap, so there is no way to fix this bug. However if you approach the sql:query differently you can work around this issue. Consider the following code that avoids using the row data:
<%-- Get the column names for the header of the table --%>
<c:forEach var="columnName" items="${db.columnNames}">
<th><c:out value="${columnName}"/></th>
</c:forEach>
<%-- Get the value of each column while iterating over rows --%>
<c:forEach var="row" items="${db.rowsByIndex}">
<tr>
<c:forEach var="column" items="${row}">
<td><c:out value="${column}"/></td>
</c:forEach>
</c:forEach>For more information concerning this bug, see #33054
I am getting an exception - "An error occurred while evaluating custom action attribute ...". Why?
Chances are this is the issue reported by Luca Conte (#34153) and solved by Bill Stilwell. If your beans lack setters for the properties being obtained then from JDK 1.4.2_06 onwards this results in an exception. The workaround is to add a set method for the property.
The out tag is not handling my paramater named 'param'. Why not?
The following parameters should be treated as reserved words and not be used as developer variable names:
- pageContext
- pageScope
- requestScope
- sessionScope
- applicationScope
- param
- paramValues
- header
- headerValues
- initParam
- cookie
If you do use them as variable names, your mileage may vary. For more information, please see #40870. If you do need to use such a variable, then you can work around the keyword by referring to them within the pageScope as follows:
<c:out value="${pageScope.param}"/>
My XML tag is resulting in "Content is not in prolog" - why?
This is an error from the XML parser and appears to usually mean that the parser junk input. Most likely you have the filename wrong (reported as #41224).
The last() and position() functions are not working within x:forEach - why?
Not a clue
It appears to be an aspect of how the Standard Taglib is calling Xalan and the solution is not readily apparent. The bug is tracked in #22765.
When trying to serialize XML using the Xerces (2.3.0) version that ships with JSTL 1.0.5 with JDK 1.3.1.07 I get an InvocationTargetException
For example, you might get:
java.lang.reflect.InvocationTargetException: java.lang.NoSuchMethodError
at
org.apache.xml.serialize.IndentPrinter.breakLineIndentPrinter.java:281). when trying to serialize a XML document.
- This is due to a bug in Xerces. It doesn't apply to JSTL 1.1.x, as 1.1.x does not depend on Xerces. There are presently no plans to release a new version of the 1.0.x branch, but a workaround of sorts can be found by by recompiling Xerces with a JDK version higher than 1.3.1_07 (1.3.1_11 is reported to work). Using a later version of Xerces may also suffice.