Image byte [] to response.outputStream in Grails leads to “Cannot forward after response has been committed”

后端 未结 2 1179
不思量自难忘°
不思量自难忘° 2020-12-21 06:46

In my Grails controller I have an image as byte []. I want to write this byte [] directly to the response.outputStream

I use the following code to do that:

相关标签:
2条回答
  • 2020-12-21 07:11

    Grails don't know that you've already processed response, and if you aren't returning anything grails tries to apply default logic.

    Put

    return null
    

    at the end of your action.

    0 讨论(0)
  • 2020-12-21 07:20

    The error you are showing has to do with at what point the code you posted gets executed. The exception says

    java.lang.IllegalStateException: Cannot forward after response has been committed

    An HttpServletResponse is typically committed, ie. the headers are sent, when you start writing to its OutputStream. At this point you cannot change the headers or status code and you cannot use a RequestDispatcher to forward() the request to another resource.

    Check if you are doing any of these things.

    0 讨论(0)
提交回复
热议问题