最后,我以某种方式设法做到了……问题出在JSP的“ Out.write”上,它无法写入字节流……
我用servlet替换了jsp文件…
该代码段是:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { String filename = (String) request.getAttribute("fileName"); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename="+filename); File file = new File(filename); FileInputStream fileIn = new FileInputStream(file); ServletOutputStream out = response.getOutputStream(); byte[] outputByte = new byte[(int)file.length()]; //copy binary contect to output stream while(fileIn.read(outputByte, 0, (int)file.length()) != -1) { out.write(outputByte, 0, (int)file.length()); } }现在,我可以下载所有类型的文件了。
感谢您的回应:)



