aspose file tools*
The moose likes JSP and the fly likes Where does JSTL $data come from? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Where does JSTL $data come from?" Watch "Where does JSTL $data come from?" New topic
Author

Where does JSTL $data come from?

Benjamin Weaver
Ranch Hand

Joined: Apr 08, 2003
Posts: 161
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

Joined: Jan 10, 2002
Posts: 61653
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where does JSTL $data come from?