Java Spring serialize json to view -
looking output json object on jsp view within java spring. when perform following see java object tostring()
@requestmapping(value = "/home", method = requestmethod.get) @responsebody public modelandview homepage() { mapdaoimpl mapdaoimpl = (mapdaoimpl) appcontext.getbean("mapdaoimpl"); returnlocations[] daoresponse = mapdaoimpl.getpropertiesjsfilter(params); modelandview model = new modelandview(); model.setviewname("home"); model.addobject("locations", daoresponse); return model; }
jsp
<script> <c:out value="${locations}" /> </script>
edit solution:
objectwriter ow = new objectmapper().writer().withdefaultprettyprinter(); string json = ow.writevalueasstring(daoresponse); modelandview model = new modelandview(); model.setviewname("home"); model.addobject("locations", json); return model;
just serialize returnlocations[]
json inside handler method, store result in string
, add string
model
. you'll have access in jsp through request attributes.
an alternative render html page javascript sends request separate api returns json directly (serialized @responsebody
example). can whatever want result.
Comments
Post a Comment