我尝试在g:uploadForm提交后重定向页面。
我的g:uploadForm操作已保存。
保存如下:
@Transactional
def save(DesignCategory designCategoryInstance) {
if (designCategoryInstance == null) {
notFound()
return
}
if (designCategoryInstance.hasErrors()) {
respond designCategoryInstance.errors, view: 'create'
return
}
def disotypeFile = request.getFile('disotype1')
if(!disotypeFile.empty){
print('here')
def fname = disotypeFile.getOriginalFilename()
def fileAtt = new FileAttachment()
fileAtt.originalFilename = fname
fileAtt.newFilename = "disotype-"
fileAtt.fileURI = '/Users/work/Desktop/files/' + fileAtt.newFilename
disotypeFile.transferTo(new File(fileAtt.fileURI))
response.sendError(200, 'Done')
fileAtt.save(flush: true)
designInstance.disotype = fileAtt;
}
designCategoryInstance.save flush: true, failOnError:true
flash.message = message(code: 'default.created.message', args: [message(code: 'designCategoryInstance.label', default: 'DesignCategory'), designCategoryInstance.id])
redirect designCategoryInstance
}
这给出了以下错误:
Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response.. Stacktrace follows:
Message: Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response.
如果我拿出
def disotypeFile = request.getFile('disotype1')
但显然我无法获取文件。
有任何想法吗?
最佳答案
尝试删除行:
response.sendError(200, 'Done')
关于grails - Grails在uploadForm之后重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21116972/