下载excel文件(旺铺助手)的方法
//下载服务器上的模板def downloadLocal() throws FileNotFoundException {String fileName = params.filename;//文件名称String filePath = request.getRealPath("/")+"download\\"+fileName //获得物理路径(部署路径)//中文文件名称乱码情况会出现,下载的文件名看不见“.xls[1]”的情况,使用new String(fileName.getBytes(), "iso8859-1"))失败//改成URLEncoder.encode(fileName,"UTF-8")成功解决乱码。response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName,"UTF-8"));// 设定输出文件头response.setContentType("application/msexcel"); // 定义输出类型InputStream inStream = new FileInputStream(filePath);// 文件的存放路径// 循环取出流中的数据byte[] b = new byte[100];int len;try {while ((len = inStream.read(b)) > 0)response.getOutputStream().write(b, 0, len);inStream.close();} catch (IOException e) {e.printStackTrace();}}