我的下载代码如下:
<%@ page contentType="text/html;charset=gb2312" import="com.jspsmart.upload.*,java.io.*,java.net.*" %>
<%
int buffsize = 1024*2;
String strFileName = "002.xml";
String strFileURL = "ITService\\uploadfiles\\"+strFileName;
response.setContentType( "application/none" );
response.setHeader("Content-disposition","attachment; filename=" + strFileName );
try{
URL url=new URL(strFileURL);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream());
byte[] buff = new byte[buffsize];
int bytesRead;
while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
bos.write(buff,0,bytesRead);
}
if (bis!=null){
bis.close();
}
if (bos!=null){
bos.close();
}
}catch(IOException ioe){
// System.out.println("IOException at download file!"+ioe.getMessage());
ioe.printStackTrace();
}
%>
运行后文件能下载但是Tomcat会报异常,如下:
<%@ page contentType="text/html;charset=gb2312" import="com.jspsmart.upload.*,java.io.*,java.net.*" %>
<%
int buffsize = 1024*2;
String strFileName = "002.xml";
String strFileURL = "ITService\\uploadfiles\\"+strFileName;
response.setContentType( "application/none" );
response.setHeader("Content-disposition","attachment; filename=" + strFileName );
try{
URL url=new URL(strFileURL);
BufferedInputStream bis = new BufferedInputStream(url.openStream());
BufferedOutputStream bos = new BufferedOutputStream( response.getOutputStream());
byte[] buff = new byte[buffsize];
int bytesRead;
while (-1!=(bytesRead=(bis.read(buff,0,buff.length)))){
bos.write(buff,0,bytesRead);
}
if (bis!=null){
bis.close();
}
if (bos!=null){
bos.close();
}
}catch(IOException ioe){
// System.out.println("IOException at download file!"+ioe.getMessage());
ioe.printStackTrace();
}
%>
运行后文件能下载但是Tomcat会报异常,如下:
解决方案 »
- jsp获取数据库float数据,怎么样去掉小数后面的0
- 简单修改sql语句
- 怎么用JSP生成一份试卷???
- 如何获取提交页的路径?
- 奇怪的问题:谁知道这个class?在什么包中的那个版本中发布的?
- 请教rs.absolute()的问题!
- jsp中知道一个变量 year=1999;查找year表的select语句怎么写("select * from ....")
- 如何在java中将字符串转为整形
- 请教高手一个byte[] 数组传递的问题,高手请进,在线等
- javaweb 客户端批量打印求助
- 在2003服务器上遇到的奇异的问题。
- 关于jspSmartUpload下载文件的问题!很急...在线等,大侠们帮帮!
在那里看看有无能回答你的,谢谢,LZ,甭忘了给俺分哦,谢谢LZ
这里有一个文件上传组件 你可以下载看看
这个组件可以看到源代码的。
给你参考