![]() Public ActionForward export(ActionMapping mapping, ActionForm form, Here i show my struts example to demonstrate how to directly write data into InputStream and output it as “temp.cvs” to let user download. InputStream in = new ByteArrayInputStream(sb.toString().getBytes("UTF-8")) ![]() ![]() StringBuffer sb = new StringBuffer("whatever string you like") While(fileIn.read(outputByte, 0, 4096) != -1)Įxport database data or string directly to InputStream for user download. ServletOutputStream out = response.getOutputStream() We can also specified a download file name in attachment filename=, above example export a csv file name “downloadfilename.csv” for user download.Ģ) There have 2 ways to let user download a file from websiteįile file = new File("C:\\temp\\downloadfilename.csv") įileInputStream fileIn = new FileInputStream(file) "attachment filename=downloadfilename.csv") tContentType("application/octet-stream") No matter you are using struts, JSP, Spring or whatever other java framework, the logic is same.ġ) First we have to set HttpServletResponse response to tell browser about system going to return an application file instead of normal html page Here i show a simple java example to demonstrate how to let user download a file from website.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |