⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 downfile.jsp

📁 一个oa系统
💻 JSP
字号:
<%@ page language="java" contentType="application/x-msdownload" import="java.io.*" pageEncoding="gb2312"%><%
	
	String fname = request.getParameter("fname");
	String fd = request.getParameter("fd");

	//String fileName = "文档.xls";// = java.net.URLEncoder.encode(as, "UTF-8");
	/* 根据request的locale 得出可能的编码,中文操作系统通常是gb2312 */
	//fileName = new String(fileName.getBytes("GB2312"), "ISO8859-1");
	response.setContentType("application/x-download");
	response.setHeader("Content-disposition", "attachment; filename="
			+ fname + "");

	fname = new String(fname.getBytes("ISO8859-1"), "GB2312");

	BufferedInputStream bis = null;
	BufferedOutputStream bos = null;
	try {
		bis = new BufferedInputStream(new FileInputStream(
		            "d:\\oafile\\document\\" + fname.replace(".", "[" + fd + "]" + ".")));
		bos = new BufferedOutputStream(response.getOutputStream());

		byte[] buff = new byte[2048];
		int bytesRead;

		while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
			bos.write(buff, 0, bytesRead);
		}
	} catch (final IOException e) {
		System.out.println("出现IOException." + e);
	} finally {
		if (bis != null)
			bis.close();
		if (bos != null)
			bos.close();
		out.clear();
		out = pageContext.pushBody();
	}
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -