groovy - Grails error using HttpServletResponse to export file for download -


I am using the application in my Grails application to export CSV explains responsible to your individual domain class. I am getting the following error, however: for the servlet [default] in the reference with the path [/ MyApp]

Servlet.service () threw the exception [request processing failed; Error in processing GroovyPageView: nested exception org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException getOutputStream () has already been called for this response] with the original reason message: getOutputStream () already This response has been called for

From online search, I think the answer may be anywhere to apply a response to the HTTPSvette response. However, I'm not sure how to do this. any idea? Here is my code:

  def export = {df course = course.gate (params.id) if (course) {def persons = course? Person.findAllByCourse (Course): [] response.setHeader ("Content-Properties", "Attachment; File Name = People.csv") response.contentType = "text / CSV" = response.outputStream out.withWriter {Author out DEF - & gt; String [] attribute = new string [3] def csvWriter = new CSV author (author) person Ish {person - & gt; Properties [0] = person.firstName Properties [1] = person.lastName Properties [2] = person.email Properties [3] = person.phone Properties [4] = person.address1 Properties [5] = person.address2 Properties [ 6] = person.city property [7] = person.state attribute [8] = person.zip5 csvWriter.writeNext (attribute)} csvWriter.flush ()}}    

Your problem is obviously created by writing the output stream in your controller, after which you return from your operation after the default behavior of GSP rendering On. You can check the second case of this, with some fixes I do not need grails on the machine I'm at present to re-issue this, but can help to stop at the end of Looks like adding a clear returning null Or render . Produce some token output or 200 status codes via

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -