查了不少文章,还是找不到原因,我的下载页面代码如下:
downloas.jsp:
<%
java.io.BufferedInputStream bis=null;
java.io.BufferedOutputStream bos=null;
try{
String filename=request.getParameter("filename");//接收文件名
String path=request.getParameter("path");//接收传递路径
filename=new String(filename.getBytes("iso8859-1"),"gb2312");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
bis =new java.io.BufferedInputStream(new java.io.FileInputStream("e:\\ftp\\"+path+"\\"+filename));
bos=new java.io.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(Exception e){
e.printStackTrace();
}
finally {
if (bis != null)bis.close();
if (bos != null)bos.close();
}
%>
downloas.jsp:
<%
java.io.BufferedInputStream bis=null;
java.io.BufferedOutputStream bos=null;
try{
String filename=request.getParameter("filename");//接收文件名
String path=request.getParameter("path");//接收传递路径
filename=new String(filename.getBytes("iso8859-1"),"gb2312");
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
bis =new java.io.BufferedInputStream(new java.io.FileInputStream("e:\\ftp\\"+path+"\\"+filename));
bos=new java.io.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(Exception e){
e.printStackTrace();
}
finally {
if (bis != null)bis.close();
if (bos != null)bos.close();
}
%>
解决方案 »
- org.codehaus.xfire.fault.XFireFault: 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。
- servle跳转jsp
- rs.getString("姓名")为什么就不行呢
- 大家在开发STRUTS时,一个最简单的关于美工怎么处理STRUTS代码的问题
- 《100分》从数据库读取时间问题
- struts操作数据库的问题
- 在javabean从数据库中读出数据,在将数据从javabean传到jsp的问题?
- 高分求fullcalendar 高手,
- 将domino中的数据转移到sqlser2000中
- 请问在jsp文件中(不用bean)可以用函数吗?应该不能吧?
- java mail用imap收取邮件怎么做,求解答!!!!
- 关于glassfish
这两行代码什么意思?先把filename编码从iso8859-1转成gb2312
然后又把filename编码从gb2312转成iso8859-1 !!!为什么要这么做?
filename=new String(filename.getBytes("iso8859-1"),"gb2312");
response.setHeader("Content-disposition","attachment; filename="+new String(filename.getBytes("gb2312"),"iso8859-1"));
再有一个你ftp的编码设的是什么?