JSP文件下载
2012-03-05 12:30
323 查看
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="java.io.File"%> <%@page import="java.io.InputStream"%> <%@page import="java.io.FileInputStream"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB18030"> <title>Insert title here</title> </head> <body> <% response.setCharacterEncoding("gb18030"); System.out.println("path1:" +request.getSession().getServletContext().getRealPath("/")); String name = request.getSession().getServletContext().getRealPath("/").replace("\\","/") + "downloadfiles/outlook邮件归类.docx"; File downFile = new File(name); response.setContentType("binary/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=" + new String(downFile.getName().getBytes("gb2312"), "iso8859-1")); ServletOutputStream servletOutputStream = response .getOutputStream(); InputStream is = new FileInputStream(downFile); byte[] bytes = new byte[1024]; while (true) { int chunk = is.read(bytes); if (chunk == -1) { break; } servletOutputStream.write(bytes, 0, chunk); } is.close(); %> </body> </html>
相关文章推荐
- JSP隐含对象response实现文件下载的两种方法
- 简单文件下载jsp
- 用jsp实现直接下载文件的功能
- JSP文件下载
- 访问JSP文件或者Servlet文件时提示下载的解决方法
- jsp中文件下载的实现
- 最简洁简单的JSP下载文件的方式。
- jsp文件下载
- struts2的jsp页面下载文件
- jsp文件在ie中打开时提示下载的错误
- jsp文件的上传和下载操作代码
- JSP下载文件,直接下载文件保存到本地,不直接打开,没有乱码
- jsp 下载 服务端的文件到本地
- 使用JSP+Servlet实现文件上传下载
- 由response.setContentType()方法 + JSP/Servelt上传下载文件
- JSP servlet实现文件上传下载和删除
- jspsmart实现文件的上传与下载
- JSP文件下载中文和空格显示Content-Disposition设置
- 解决JSP文件下载时文件名乱码问题
- 关于jsp中的文件下载