Is it possible to convert jstl/JSP variables to javascript variables?
Here is the JSTL:
<c:forEach var="responseString" items = "${responseString}">
<c:out value="${responseString.response}" />
</c:forEach>
I want to transfer the value inside ${responseString.response} to a javascript var response
HERE is the javascript function:
directionsService.route(request, function(response, status)
I tried this tutorial;
var response = {
<c:forEach var="responseString" items = "${responseString}">
<c:out value="${responseString.response}" />
</c:forEach>
}
Obviously it didn't work, I kind of screwed it up, please help.
Added info, ${responseString.response} is actually JSON, I just converted it to String:
{"routes": [{"bounds" : {"northeast":{"lat":14.650,"lng":121.050610}, "status":"OK"}
It's a deeply nested JSON.
Do something like this:
var availableTags = [
<c:forEach items="${vendorMap}" var="vendor" varStatus="vendorStatus">
'<c:out value="${vendor}" />'
<c:if test="${!vendorStatus.last}">
,
</c:if>
</c:forEach>
];
Note that you should not add "," for the last entry and also single quotes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With