Wednesday, June 13, 2007

Correction: JSTL and expression language problem

In my older post I wrote about problem in using JSTL.
For a summary, my problem is I kept seeing this error message:
According to TLD or attribute directive in tag file, attribute value does not accept any expressions

And I find out that problem occurs because I was using JSTL-1.0 in a JSP-2.0 environment. Details can be found here.

Lately, when working on my project and using JSTL again I come against a strange problem. I am trying to use <c:out value="${foo.bar}" /> and it simply prints ${foo.bar}.

After a quick inspection I found the source of the problem. Again I made mistake using auto-complete in IntelliJ ( sometimes i found this after error occurs, like this time:) ).
So using auto complete, i define core taglib definition like this:
<%@ taglib prefix="c" 
uri="http://java.sun.com/jsp/jstl/core"%>

This definition is for JSTL-1.1 and guess what I am using JSTL-1.1 jar and Servlet-2.3/JSP-1.2 web-app(due to some code-generation issues). So i fix this error by changing tld description like this:
<%@ taglib prefix="c" 
uri="http://java.sun.com/jstl/core"%>

In conclusion of my older post I state :

So here is the summary for all of my words:
  • Servlet 2.3/JSP 1.2 + JSTL 1.0 - OK
  • Servlet 2.3/JSP 1.2 + JSTL 1.1 - OK
  • Servlet 2.4/JSP 2.0 + JSTL 1.1 - OK
  • Servlet 2.4/JSP 2.0 + JSTL 1.0 - PROBLEM

If problem occurs first check web.xml and JSTL verisons.
Upgrade if you can (highly recommended), if you can't then use "c-rt.tld"

This is still true. BUT if you want to use Servlet 2.3/JSP 1.2 + JSTL 1.1 option, you should avoid using JSTL-1.1 tld definition.

7 comments:

Geckelberryfinn said...

Hi!

I have some problems with jstl and may be you can help me?
I'm trying to move an application from Tomcat to IBM Websphere Community Edition (WASCE). Under tomcat application works correctly, but after deploying it in WASCE, jstl expressions do not parse if jsp located not in the root directory. In other word, in html source that accepted by browser, constructions like "${}" are presented.
Application uses jstl-1.1.2
Header of the web.xml is
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

Alper Köse said...

Did you check what JSTL version your TLD uses (1.0 or 1.1).
if you use TLDs from jar:
- http://java.sun.com/jstl/core refers to JSTL-1.0 on JSP-1.2/Servlet-2.3
- http://java.sun.com/jsp/jstl/core refers to JSTL-1.1 on JSP-2.0/Servlet-2.4

Since you say "Under tomcat application works correctly, but after deploying it in WASCE, jstl expressions do not parse if jsp located not in the root directory." I doubt this problem is because of some WASCE issue.

Does your application in WASCE throw some Exception or simply prints EL to html??

Geckelberryfinn said...

First (Login) page simply prints EL to HTML, but other pages produced a error, for example:

org.apache.jasper.JasperException: For input string: "${currentPage}"

In all probability JSTL 1.1 are used, because TLD is following:


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


In addition, "standart-examples" application, which supply with jakarta-taglibs-standatrd-1.1.2 works correctly under WASCE. And if i copy one jsp of my application in the root directory from /WEB-INF/jsp/ then it's ELs are parsed.

Alper Köse said...

I can't understand why it is working under /WEB-INF/jsp/ nor can I explain why it is not working under root directory. Maybe WASCE handles root directory and directories under WEB-INF differently. I don't have any experience on WASCE so i can't blame it :)
But your TLD description might prevent parsing EL since it expects this from JSP engine.
Can you try http://java.sun.com/jstl/core as a TLD??
Or you can use Servlet-2.4, but for this you must change your web.xml descriptor.

Geckelberryfinn said...

Ok. Thank you. In web.xml i changed

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


to the

<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 web-app_2_4.xsd"
version="2.4">

and now application working good!

Alper Köse said...

Glad to help :)

Paul W Wallace said...

Based on the previous dialog with AISA, is it the case that the problem was solved by changing the Servlet API to 2.4? Does this mean that JSTL 1.1 will not work with Servlet API 2.3?

I'm investigating a problem where XML JSTL is not working and I'm constrained to J2EE 1.3 with Servlet 2.3 and JSP 1.2 - my understanding was that I could only use JSTL 1.0.
When I include the taglib reference

<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>

in a jsp, without adding any JSTL code, I get an stream of exceptions related to the XML:

org.xml.sax.SAXParseException: Content is not allowed in prolog.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)

Inclusion of the core taglib reference does not cause a problem:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>


Can you recommend a newsgroup to post such a question?