java - Sending text file to client through Spring MVC web application -
after doing research online on subject managed things working code:
@requestmapping(value = "/report040generated", method = requestmethod.get) public string index(model model, httpservletresponse response, httpservletrequest request) throws ioexception { string mystring = "hello"; response.setcontenttype("text/plain"); response.setheader("content-disposition","attachment;filename=myfile.txt"); servletoutputstream out = response.getoutputstream(); out.println(mystring); out.flush(); out.close(); return "index"; }
my proble when click on jsp button, files gets downloaded method doesn't redirect "index" .jsp view , gives me illegalstateexcepton:
severe: servlet.service() servlet jsp threw exception java.lang.illegalstateexception: getoutputstream() has been called response
any suggestions might causing issue ?
it not possible redirect page when returning file file http response. explanation here: spring - download file , redirect
Comments
Post a Comment