@RequestMapping(value = "/download", method = RequestMethod.GET)
public @ResponseBody
void downloadFile(HttpServletResponse resp) {
String downloadFileName= "download.txt";
String downloadStringContent="Download text \n This is working.";
try {
OutputStream out = resp.getOutputStream();
resp.setContentType("text/plain; charset=utf-8");
resp.addHeader("Content-Disposition","attachment; filename=\"" + downloadFileName + "\"");
out.write(downloadStringContent.getBytes(Charset.forName("UTF-8")));
out.flush();
out.close();
} catch (IOException e) {
}
}
(Ganesh Tiwari) gt_ebuddy's Blog - Code snippets, technical articles, tips on computing and programming...
java servlet/jsp download string into text file - spring controller method
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Your Comment and Question will help to make this blog better...