Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java spring framework - how to set content type?

I have a spring action that I am rendering some json from the controller, at the minute its returning the content type 'text/plain;charset=ISO-8859-1'.

How can I change this to be 'application/json'?

like image 495
Ian morgan Avatar asked Apr 09 '10 08:04

Ian morgan


1 Answers

Pass the HttpServletResponse to your action method and set the content type there:

public String yourAction(HttpServletResponse response) {
    response.setContentType("application/json");
}
like image 115
Bozho Avatar answered Oct 11 '22 09:10

Bozho