日期:2014-05-18  浏览次数:20772 次

java文件下载,在下载对话框中没有显示自己给定的文件名
本人写了一个下载文件的类,下载文件时,文件能够被下载,但是默认的文件名不是我想要的文件名:

public   class   DownloadCSVFileAction   extends   Action{
        public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,   HttpServletRequest   request,   HttpServletResponse   response)   throws   Exception   {                

                try   {                        
                        String   fileName   =   request.getParameter( "fileName ");
                        long   maID   =   Long.parseLong(request.getParameter( "maID "));
                        String   filePath   =   request.getSession().getServletContext().getRealPath( "/ ")+ "csv/ "+maID+ "/ "+fileName;
                        File   fdown   =   new   File(filePath);
                        int   filelength   =   Integer.parseInt(String.valueOf(fdown.length()));
                     
                        response.setContentType( "application/text;charset=GB2312 ");
                        response.setHeader( "Content-Dispositon ", "attachment;filename=销售详细记录.csv ");     //销售详细记录.csv是我想要的下载文件的文件名,但是下载对话框中显示的是   downLoadCSVFile.do
                       
                        response.setContentLength(filelength);
                        byte   b[]=new   byte[filelength];
                        FileInputStream   fi=new   FileInputStream(fdown);                      
                       
                        OutputStream   o=response.getOutputStream();
                        int   n   =   0;
                        while((n=fi.read(b))!=-1)   {
                                o.write(b,0,n);
                        }
                        fi.close();
                        o.close();