Data processing
Hello
I have the requirement that data returned by server be processed by both jsp as well as other java script code.
How can I achieve it
eg:--
My java controller is returning
modelMap.put("saved", saved);
and in jsp I am using it as
<select style="width:100" id="saved" name="listSavedSearches" class="blackText" onchange="getSavedQueryResults();">
<c:forEach items="${saved}" var="saved">
<option value="${saved.id}">
${saved.name}
</option>
</c:forEach>
</select>
Now I have the requirement of acessing data $(saved) in my js file.
How can I achieve it.
Thanks
With regards
[730 byte] By [
Rojara] at [2007-11-26 15:35:14]

# 1
The same way you access it in your normal jsp code.
The ${} elements in your javascript will be evaluated and it would be this evaluated value that appear in the javascript on the browser.
To illustrate, assume you have a variable called greeting whose value is 'Hello World'. To use this in a javascript in your jsp file, say, as an alert message, you would
<script>
alert("Here's a greeting "+${greeting});
</script>
Now when this jsp is requested, the server executes the entire jsp and evaluates all the jsp content, including the one in your script so that the html output flushed to the browser would be
<script>
alert("Here's a greeting Hello World); //note the variables is evaluated
</script>
Does this help?
Btw, in the code you had posted,
<c:forEach items="${saved}" var="saved">
<option value="${saved.id}">
${saved.name}
</option>
</c:forEach>
you would have to use a different variable for 'var' attribute as the one you have used, namely 'saved', is already used up before.
ram.