接上篇,通过javabean能够在jsp页面打开chm帮助文件,但是在客户端就不可以打开了。后来想到一个方法。点击链接通过下载。首先把chm文件放到压缩包内,通过getRealPath()得到相对路径。然后利用java io包中的FileInputStream写出。就可以下载。<%@ page import="java.io.*" %> <% String fileName = request.getParameter("ID"); fileName=new String(fileName.getBytes("ISO8859_1"),"gb2312"); response.setContentType("APPLICATION/OCTET-STREAM"); response.addHeader("content-type", "application/x-msdownload;"); response.setHeader("Content-disposition","attachment; filename=SUDA_ERP_" + fileName +".rar" ); String path=application.getRealPath("")+"help"+".rar"; java.io.FileInputStream fileInputStream = new java.io.FileInputStream(path); // 写出流信息 int i; while ((i=fileInputStream.read()) != -1) { out.write(i); } fileInputStream.close(); out.close();%>