Forums Register Login

Where does JSTL $data come from?

+Pie Number of slices to send: Send
The JSTL example code listed below is straightforward enough. But where does the ${customers} collection come from? The ServletContext? the session? the request? what is the default reference?
In other words, what in JSTL establishes the linkage between underlying data bean and the jsp variable reference of the kind provided in other libraries by the usebean directive?
What if, for example, an application maintained--by bad coincidence--two different customers collections of the same name, one in ServletContext and one in request? How would each be referenced in JSTL?
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
<title>JSTL: Iterator Support -- Simple Iteration Example</title>
</head>
<body bgcolor="#FFFFFF">
<h3>Simple Iteration</h3>
<h4>Customer list</h4>
<c:forEach var="customer" items="${customers}">
<c ut value="${customer}"/><br>
</c:forEach>
</body>
</html>
+Pie Number of slices to send: Send
If you do not specify a scope, the variable will be searched for in page, request, session and application scopes, in that order.

What if, for example, an application maintained--by bad coincidence--two different customers collections of the same name, one in ServletContext and one in request? How would each be referenced in JSTL?


An unqualified reference will link to the instance stored in request context since it is searched before application context (aka Servlet Context).
If you want to look only in a specific scope, you can qualify the reference; ${requestScope.whatever} for example.
[ March 30, 2004: Message edited by: Bear Bibeault ]
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1188 times.
Similar Threads
need a help regarding "JSTL with xml tag"
jspx file not working with foreach
EL does not work
Ajax with JSP and JSTL
Calling a new JSP form a Spring Controller using Ajax
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 15:23:25.