Reputation: 53
In my spring controller, I have created a json :
{
"productsData": [
{
"code": "0100",
"name": "Shirt",
"summary": "Shirt for males"
},
{
"code": "0101",
"name": " Shirt 1",
"summary": "Shirt for males"
},
{
"code": "0102",
"name": "Shirt 2",
"summary": "Shirt for males"
}
]
}
And added this json to model attribute as :
model.addAttribute("productsJson", responseDetailsJson.toString());
When I am getting values from json
on jsp
as :
<c:if test="${not empty productsJson}">
<c:out value="${productsJson.productsData}"></c:out>
<c:forEach var="product" items="${productsJson.productsData}">
</c:forEach>
The exception is :-
${productsJson.productsData}' Property 'productsData' not found on type java.lang.String
Upvotes: 1
Views: 4666
Reputation: 2524
The error is produced because you are trying to use productsData
from an String. If you want to use this property you shouldn't use toString
method in the controller.
Even if you use productsJson.productsData
, I don't think is the correct way to call it. Most likely you should use productsJson['productsData']
. This is because productsJson
is a Map
not an Object
Upvotes: 2