Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where does JSTL $data come from?

 
Benjamin Weaver
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • 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>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65109
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic