Thank you for your visiting.
I use the following code to download a file in the Action class of my custom JIRA plugin.
File file=new File(fileSavePath+"\\"+testFile);
HttpServletResponse response = ServletActionContext.getResponse();
response.setHeader("Content-Disposition", "attachment;filename=" + testFile);
FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream();
byte buffer[] = new byte[1024];
int len = 0;
while((len=in.read(buffer))>0){
out.write(len);
}
in.close();
out.close();
But exception always occurs,
java.lang.IllegalStateException: response.getWriter() called after response.getOutputStream()
at com.opensymphony.module.sitemesh.filter.Buffer.getWriter(Buffer.java:72)
at com.opensymphony.module.sitemesh.filter.PageResponseWrapper$3.activateDestination(PageResponseWrapper.java:100)
at com.opensymphony.module.sitemesh.filter.RoutablePrintWriter.getDestination(RoutablePrintWriter.java:42)
at com.opensymphony.module.sitemesh.filter.RoutablePrintWriter.write(RoutablePrintWriter.java:141)
at com.atlassian.velocity.DefaultVelocityManager.exceptionHandling(DefaultVelocityManager.java:154)
at com.atlassian.velocity.DefaultVelocityManager.writeEncodedBodyImpl(DefaultVelocityManager.java:123)
at com.atlassian.velocity.DefaultVelocityManager.writeEncodedBody(DefaultVelocityManager.java:97)
at com.atlassian.jira.template.velocity.DefaultVelocityTemplatingEngine$DefaultRenderRequest.toWriterImpl(DefaultVelocityTemplatingEngine.java:122)
at com.atlassian.jira.template.velocity.DefaultVelocityTemplatingEngine$DefaultRenderRequest.asHtml(DefaultVelocityTemplatingEngine.java:113)
does it mean that I should not use method of getOutputStream()?
Thank you.