title: Sending text file to client through Spring MVC web application
body: <p>After doing some research online on the subject I currently managed to get things working with this code:</p>
  
  <pre><code>@RequestMapping(value = "/report040Generated", method = RequestMethod.GET)
      public String index(Model model, HttpServletResponse response, HttpServletRequest request) throws IOException {
  
          String myString = "Hello";
          response.setContentType("text/plain");
          response.setHeader("Content-Disposition","attachment;filename=myFile.txt");
          ServletOutputStream out = response.getOutputStream();
          out.println(myString);
          out.flush();
          out.close();
  
          return "index";
      }
  </code></pre>
  
  <p>My proble is that when I click on my JSP button, the files gets downloaded but the method doesn't redirect to the "index" .jsp view and gives me an IllegalStateExcepton:</p>
  
  <p><em>SEVERE: Servlet.service() for servlet jsp threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response</em></p>
  
  <p>Any suggestions about what might be causing this issue ?</p>