0

I'm using Spring MVC and I've run into a lot of issues with cross dependencies of JSTL. Is there an effective way of accessing a model attribute from within raw jsp? For instance, how could I translate this loop WITHOUT using JSTL?

<tbody>
    <c:forEach items="${things}" var="thing">
        <tr>
            <td><c:out value="${thing.name}"/></td>
            <td><c:out value="${thing.description}"/></td>
        </tr>
    </c:forEach>
</tbody>

I've tried a few variants on

<tbody>
    <% for (int i = 0; i < ${things}.length; i++ %>
        <tr>
            <td><${things[i].name}/></td>
            <td><${things[i].description}/></td>
        </tr>
    </c:forEach>
</tbody>

But I can't get the syntax correct and almost every example on the web uses JSTL.

P.S. I expect to be blasted for ditching JSTL, but seriously this error is ridiculous:

java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
Brian Dolan
  • 3,086
  • 2
  • 24
  • 35
  • It might be interesting to have a look at other questions and articles regarding that specific error, looks like there may just be a version mismatch - eg http://stackoverflow.com/questions/542383/why-do-i-get-an-abstractmethoderror-when-setting-a-jstl-variable and http://forum.springsource.org/showthread.php?63077-java-lang-AbstractMethodError . I'd only revert back to scriptlets if you're really out of other options. – fvu Mar 05 '13 at 15:50
  • Thanks @fvu All the proposed solutions suggest "remove jstl-*jar from your WEB-INF/lib directory, but I'm using maven and have tried 1000 variants on – Brian Dolan Mar 05 '13 at 16:35
  • Hmm, what about making its dependency `provided`? That way it won't be distributed in the war. – fvu Mar 05 '13 at 17:08
  • THat's a good idea and I'm searching for which one to scope out of these: com.springsource.javax.servlet, (currently provided) com.springsource.javax.servlet.jsp.jstl,com.springsource.javax.servlet.jsp (currently provided) and com.springsource.org.apache.taglibs.standard I get CNFE if I take the last two out. – Brian Dolan Mar 05 '13 at 17:20
  • I think I found a solution to the JSTL problem, a boat-load of exclusions: http://stackoverflow.com/questions/542383/why-do-i-get-an-abstractmethoderror-when-setting-a-jstl-variable/15231992#15231992 – Brian Dolan Mar 05 '13 at 19:06
  • if the track you're following now leads to a solution please add it as an answer, so that future visitors can learn how to solve the problem, thanks! – fvu Mar 05 '13 at 22:36

2 Answers2

3

Let me preference the following with this: Using JSTL is considered "best practices"

That said, nothing is stopping you from using scriptlets to access model objects. For instance, you could do something like:

<%
  Foo foo = null;
  foo = (Foo)request.getAttribute("foo");
%>

But, again, this is not really a recommended approach.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • Thanks @CodeChimp I would LOVE an alternative to JSTL at this point. It would be nice if it worked... – Brian Dolan Mar 05 '13 at 17:31
  • I have never had an issue with JSTL. I don't think you can blame it, though, for a dependency problem in your deployment. – CodeChimp Mar 05 '13 at 17:32
0

Ultimately, I ended up using JSTL (as per "best practices"). I needed to do quite a number of exclusions to over-write some dependencies introduced by Hadoop. Here is my exclusion list:

java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;Abstract Error

Community
  • 1
  • 1
Brian Dolan
  • 3,086
  • 2
  • 24
  • 35