Spring MVC: Specify MIME headers

There’s seems to be 2 options.

1) Use ResponseEntity<String> as return type:

String xml = ...
HttpHeaders responseHeaders = new HttpHeaders(); 
return new ResponseEntity<String>(xml, responseHeaders, HttpStatus.OK)

2) Use ‘produces’ attribute of @RequestMapping

@RequestMapping(value="/some/page", produces="application/xml")

Test both methods, and they seem to work equally fine.

source: http://stackoverflow.com/questions/4471584/in-spring-mvc-how-can-i-set-the-mime-type-header-when-using-responsebody

Another method seems to be by using the HttpServletResponse object: response.setHeader(“…”, “…”);

Posted in Spring, Spring MVC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: