title: Spring MVC Controller with JSON and JSP
body: <p>Can the same method in a controller be used for both JSP and other MIME types (like XML and JSON)?</p>
  
  <p>I know of the following ways to resolve views in Spring MVC.</p>
  
  <ol>
  <li>Return a <code>String</code> with the view name and add attributes to the <code>Model</code> or <code>ModelMap</code></li>
  <li>Return a <code>ModelAndView</code> with the view name and model</li>
  <li>Return an <code>Object</code> with a <code>@ResponseBody</code> annotation</li>
  </ol>
  
  <p>I use 1 or 2 when I am dealing with JSP and 3 when I want to return JSON or XML.</p>
  
  <p>I know I can use two methods and with the <code>@RequestMapping(headers="accept=application/xml")</code> or <code>@produces</code> annotations to define which MIME types they handle, but is it possible to do this in just one method?</p>
  
  <p>The controller logic is pretty simple and it seems like unnecessary duplication to have two different methods mapped which return the same exact model, or is this just simply the way it's done?</p>