mercredi 1 avril 2015

Spring Controller Return View and JSON Together

I am trying to map a page request to return a view and a JSON Object simultaneously. For this I'm utilizing the Jackson JSON provider


Here's my Controller method



@RequestMapping(method = RequestMethod.GET, value = "/reports")
public String getFiles(Model model) {
//
//build array list
//
return files;
}


This returns my view (WEB-INF/jsp/reports.jsp) fine, however without the JSON Object that Jackson builds, so of course I need to annotate the method with @ResponseBody which will write the JSON Object to the http response automagically, and return the files ArrayList...



@RequestMapping(method = RequestMethod.GET, value = "/reports")
@ResponseBody
public ArrayList<String> getFiles(Model model) {
//
///build array list
//
return files;
}


and the JSON object is indeed returned, but in a new view/blank html doc. Is it possible to return the JSON Object and redirect to "reports.jsp" at the same time?


Aucun commentaire:

Enregistrer un commentaire