Okay, I know I haven’t posted anything on my blog in over a year, but this falls under the OMG-Why-Couldn’t-I-find-a-straightforward-answer category. Whomever suffers the same headache I suffered will hopefully get led here by Google…
The Problem: Running the most basic JSP Example
Up until now, the few times I’ve needed to cobble together a JSP file for some sort of front-end functionality, I’ve used raw, low-level JSP Scriptlets. Which means typing things like
<% if (something) { %> <some-html> <% } else { %> <some-html> <% } %>
all over the place. And if I wanted to do any looping, well forget about it! It’s a nightmare. So I’ve got these few books and articles that talk about the better ways to solve these problems using cleaner xml-y solutions, and most all of them dive into using JSTL (JSP Standard Tag Library) which is a damned standard and yet isn’t included with Tomcat. It’s one of those things that each vendor is supposed to implement independently, and yet the only implementation out there appears to be Oracle’s Glassfish implementation! (There’s an Apache JSTL project, and they say on their web page that a version 1.2 implementation (which is the stated version for the Java 6 EE standard collection, alongside Servlet 3.0 and JSP 2.2) but that webpage hasn’t been updated since October 2009!!
So apparently JSTL is so basic and simple that it’s included in the elementary pages of any JSP books, but like some bastard stepchild that nobody wants, it’s support is freakishly missing. Okay, enough bellyaching about how FUBAR that is… what about just getting the thing to run?
Here are some watchas that I ran into…
- It doesn’t work… until it does. Until I had the right library dependencies working and the right namespace down, I didn’t get any error messages or diagnostics. I just found that my sample <c:forEach> tags would get merely copied into the resulting HTML.
- The JSP namespace changed. Some early books showed examples where the JSP namespace was written out as
xmlns:c="http://java.sun.com/jstl/core"when in fact it later got renamed toxmlns:c="http://java.sun.com/jsp/jstl/core"! Again, no error messages to help me out here. It just didn’t work until it did. - Dependency hell, JSTL 2.1 can include the wrong JSP API versions. More on this in the next section.
The good news is you should just be able to grab the Oracle Glassfish implementation JAR, toss that into Tomcat’s lib directory, and stop worrying. But if you use Maven for your dependency management, then life gets crazy again.
JSTL and Maven Dependencies
For the longest time I avoided learning Maven because it just seemed like “just one more thing” and besides, Eclipse seemed to handle all the packaging, etc. just fine. But once I started playing around with XML and SOAP and Web Services and Dependency Injection and Spring and all that really cool stuff, I knew I had to bite the bullet. And I’m glad I did.
Normally if I want to start using some feature (like JSTL) I’ll just do a search in my Eclipse pom dependencies pane, add the dependency and start using the thing. (It’s fantastic!) But unfortunately, Maven dependencies seem to have gotten tripped up when it comes to JSTL 1.2, the bastard stepchild of a dependency. And especially for Tomcat (6 or 7 apparently) which is the “We’re the de-facto standard Servlet 3.0/JSP 2.2 container… except for the JSTL Bastard Stepchild!” server.
When I tried to do a simple dependency inclusion…
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency>
I got the API, but no runtime libraries. (As I said in the earlier section, this doesn’t result in a compile or runtime error. The JSTL tags simply don’t run and get passed through the outgoing HTML!) So then, after looking for an Apache implementation (I wanted to keep my implementation flavors consistent, and Apache wrote the Servlet 3.0/JSP 2.2 for Tomcat) I decided to include the Glassfish implementation…
<dependency> <groupId>org.glassfish.web</groupId> <artifactId>jstl-impl</artifactId> <version>1.2</version> </dependency>
and THEN I finally got a runtime exception. But this
javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature
At least this time I got an error message, strange as it was! (And all throughout this experience I didn’t find much of use on the Internet, which is why I’m writing this blog entry.) So at least I got the general idea that there was a revision/dependency problem between the classes. This is why I really hoped to find a JSTL library by Apache—because if you stick with one “flavor” you’re less likely to run into this.
I went into the Dependency Hierarchy tab of my Eclipse POM editor, and I could see that the Glassfish Maven module I’d included also decided to include the Servlet 2.5 and JSP 2.1 libraries. So I was causing a Servlet 3.0/2.5 and JSP 2.1/2.2 clash in my class loader. I clicked on those individual components, right-clicked, asked to remove the dependency, and ended up with this:
<dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.glassfish.web</groupId> <artifactId>jstl-impl</artifactId> <version>1.2</version> <exclusions> <exclusion> <artifactId>servlet-api</artifactId> <groupId>javax.servlet</groupId> </exclusion> <exclusion> <artifactId>jsp-api</artifactId> <groupId>javax.servlet.jsp</groupId> </exclusion> <exclusion> <artifactId>jstl-api</artifactId> <groupId>javax.servlet.jsp.jstl</groupId> </exclusion> </exclusions> </dependency>
Now to reclaim the hours it took me to get this far! I almost think I should have stuck with the old JSP-style scriptlets all over the place!

This was *exactly* what I was looking for–not only the steps to make it work, but actually telling me *why* it didn’t work. I finally got it all to run. Thank you so much!
Thanks for the note. Yeah, it doesn’t happen often, but every now and then there’s a complete “hole” in the Googlable universe on a relatively large topic like this. I have no illusions of my little blog being read actively, but as long as the search engines will index it, every now and then I like to know I’ve helped someone out.
An update on the entire overall topic—and this I find rather strange—is that it seems that JSP and JSTL are dead. I am practicing in hyperbole here, but the fact of the matter is that any modern J2EE developer has moved on to either JSF or Google’s GWT. JSP may be okay for a quick “knock this small thing out” solution, but I guess the implication is that you shouldn’t really waste your time on it.
Now having said that, if you talk with corporate IT departments (and I work with some IT groups in the Fortune 50) you will find that there is plenty of active JSP development going on, and that there are few boots-on-the-ground people doing JSF. Then again, one of these companies I’ve worked with just last year moved from Java 1.4 to Java 5 (or more specifically from IBM WebSphere 5 to 6) so you can see what’s going on.
Anyway, food for thought.
I would like to add that I couldn’t get this to work with Tomcat 7.0.22. I spent an inordinate amount of time on it and then for the heck of it, downloaded 7.0.27 and it worked right out of the box with the war I had been testing with all along.
Stumbled upon your blog after 1000s of WTFs. Thank you!
Just wanted to say hi and thanks. I had an old application that was running fine under Resin that I had to move to Tomcat and then I stumbled upon this idiocy… I was including just javax.servlet.jstl/1.2 as dependency because I thought it included the reference implementation also. In many places it talks about jstl-api.jar and jstl-impl.jar so I thought a jstl.jar that includes org.apache classes would include the reference implementation… WRONG!
Instead of no message or anything, I was getting the infamous “The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application” but it seems the problem was the same…
Oh well, thanks for the heads up, it worked
.
Thank you so much. You have saved me from hell.
Thank you a lot. This really saved my day, since I was almost going nuts not understanding why it told me there’s no taglib for the given namespace.
The error message could indeed be better explained.
Thanks!
I spend a day trying find problem with JSP.
And you save me from being crazy!!!…..
Thank you so much! ))
You are a lifesaver! 2+2=4!
That’s an interesting note. I wonder what was off with that one version of Tomcat. Well, thanks for your note. Hopefully it’ll help someone else out.
Cheers!
What was supposed to be an easy to find fix took me hours to find it until I found your article. Thank you.
Phew, Google did it’s work! This saved me from smashing my PC through the window!
Nice work posting this here!
Mr. Williams
I am very thank full to you. I was googling for last 3 hours to solve this problem.
Finally I got what I was expecting.