Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
398 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...