• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Where does JSTL $data come from?

 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic