Tôi có một hành động ghi trực tiếp vào luồng đầu ra. Đôi khi tôi nhận được những điều sau đây để các lỗi:Lỗi xử lý GroovyPageView: getOutputStream() đã được gọi cho phản hồi này
Error processing GroovyPageView: getOutputStream() has already been called for this response
Caused by getOutputStream() has already been called for this response
và một này:
Executing action [getImage] of controller [buddyis.ItemController] caused exception: Runtime error executing action
Caused by Broken pipe
Làm thế nào tôi có thể giải quyết những vấn đề này? Hành động tôi sử dụng được liệt kê bên dưới.
LƯU Ý: Tôi sử dụng Tomcat 7.0.42, nếu điều này quan trọng!
def getImage() {
byte [] imageByteArray = // some image bytes
response.setHeader 'Content-disposition', "attachment; filename=\"${imageName}${imageExtension}\""
response.setContentType("image/pjpeg; charset=UTF-8")
response.contentLength = imageByteArray.size()
response.outputStream.write(imageByteArray)
response.outputStream.flush()
response.outputStream.close()
return
}
Cố gắng hiển thị một thứ gì đó (giả) để lập chỉ mục hoặc hiển thị mã trạng thái và xem liệu bạn có gặp sự cố không. Bạn có thể bắt đầu với 'render (status: 200)' hoặc ít nhất 'render" Done "' etc trước khi trả về. – dmahapatro
Tại sao thực hiện việc này? – confile
Tham khảo [câu hỏi này] (http://stackoverflow.com/questions/13184603/grails-error-using-httpservletresponse-to-export-file-for-download). – dmahapatro