posts - 14,  comments - 37,  trackbacks - 0
File file = new File(servlet.getServletContext().getRealPath("/"
                                         
+ File.separator 
                                         
+ attachment.getStorePath()) ;

                    response.setContentType(
"application/force-download") ;
                    response.setHeader(
"Content-Disposition""attachment;filename=\""+new String(attachment.getAttachName().getBytes("gb2312"), "ISO8859-1")+"\"") ;//浏览器不管这些编码,人家直接用iso8859-1给你显示,所以,这里必须手工转换编码才可以,这个地方可以参考:http://tiandl88.blogchina.com/5367140.html  不知道是不是原创地址
                    
//write to output stream
                    InputStream in = new FileInputStream(file) ;
                    ServletOutputStream out 
= response.getOutputStream() ;
                    
int byteLength = 0 ; 
                    
byte[] buffer = new byte[8192] ;
                    
while((byteLength = in.read(buffer, 08192)) != -1){
                        out.write(buffer, 
0, byteLength) ;
                    }

                    out.flush() ;
                    out.close() ;
                    in.close() ;
                } 
catch (Exception e) {
                    ActionErrors errors 
= new ActionErrors() ;
                    errors.add(
"downloadError"new ActionError("lx.error.UploadError.FileNotExists")) ;
                    saveErrors(request, errors) ;
                    ret 
= mapping.findForward("error") ;
                }

可以参考的连接有
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2183&lngWId=2
http://www.webdeveloper.com/forum/archive/index.php/t-78425.html
posted on 2007-07-10 10:22 冰封的爱 阅读(547) 评论(0)  编辑  收藏 所属分类: J2EE

只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(3)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜