export 页面
<%@page language="java" contentType="application/x-msdownload" pageEncoding="UTF-8" %>    
<%@page language="java" import="java.io.*" %>
<%@page language="java" import="java.net.URLEncoder" %>
<%@page language="java" import="java.net.URLDecoder" %>
<%@page language="java" import="com.ejpt.util.charconvert.CharConvert" %>
<%
out.clear();    
out = pageContext.pushBody();
	request.setCharacterEncoding("GBK");
	String filename = request.getParameter("filename");
	System.out.print("文件名称:"+filename+"");
	String path = request.getParameter("path");
	String df = request.getSession().getServletContext().getRealPath("/");
    //关于文件下载时采用文件流输出的方式处理:    
    //加上response.reset(),并且所有的%>后面不要换行,包括最后一个;    
  	response.reset();//可以加也可以不加
  	
  	response.setContentType("application/x-download");    
   
   
	String filedisplay =  filename;
 	String filedownload = df+path;
	//System.out.println("下载路径:"+filedownload+" end");
	File fileLen = new File(filedownload);
	long len = fileLen.length();
	response.setContentLength((int)len);
  	response.addHeader("Content-Disposition","attachment;filename=" + new String(filedisplay.getBytes("gb2312"),"iso8859-1"));    
   
  	java.io.OutputStream outp = null;    
  	java.io.FileInputStream in = null;    
  	try    
  	{    
  		outp = response.getOutputStream();
  		File file = new File(filedownload);
  		in = new FileInputStream(file);    
   
  		byte[] b = new byte[1024];    
  		int i = 0;    
   
  		while((i = in.read(b)) > 0)    
  		{    
  			outp.write(b, 0, i);    
  		}
  		
		//      
		outp.flush();    
		//要加以下两句话,否则会报错    
		//java.lang.IllegalStateException: getOutputStream() has already been called for //this response      
		out.clear();    
		out = pageContext.pushBody();    
	}
	catch(Exception e)    
	{    
	  System.out.println("Error!");    
	  e.printStackTrace();    
	}    
	finally    
	{    
	  if(in != null)    
	  {    
	  in.close();    
	  in = null;    
	  }    
	}  
%>

<html>
<head>
<title>导出Excel</title>	
</head>
	
</html>
  <a href="/swbz/pages/dmbzbzb/export.jsp?filename=sjy.doc&path=/preModel/sjy.doc" >下载</a>

阅读更多
个人分类: java
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

export 页面

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭