Try something like this (response.setHeader):

[snip]

 String savepath=DLBean.getSavePath();

 savepath+=exp+"_"+sub+"/";

 if(DLBean.getDownloadByKey(dow))
 {
  if(DLBean.getNextDownload())
    {
     String file = DLBean.getColumn("file");
     String saveasfile = DLBean.getColumn("saveasname");
     String origfile = DLBean.getColumn("origfilename");
     String mimetype = DLBean.getColumn("mimetype");

        //read the file name.
        savepath+=file;
        File f = new File (savepath);
        
        //set the content type(can be excel/word/powerpoint etc..)
        response.setContentType (mimetype);
        //set the header and also the Name by which user will be
prompted to save
        if(!saveasfile.equals(""))
          response.setHeader ("Content-Disposition", "attachment;
filename=\""+saveasfile+"\"");
        else
          response.setHeader ("Content-Disposition", "attachment;
filename=\""+origfile+"\"");

        response.setHeader("Content-Length",(new
Long(f.length())).toString() );

        InputStream in = new FileInputStream(f);
        ServletOutputStream outs = response.getOutputStream();

        int bit = 256;
        int i = 0;

        try 
        {
            while ((bit) >= 0) 
            {
                bit = in.read();
                outs.write(bit);
            }
        } 
        catch (IOException ioe) 
        {
            ioe.printStackTrace(System.out);
        }
        outs.flush();
        outs.close();
        in.close();
  }
 }
[snip]

Hope this helps.


> -----Urspr�ngliche Nachricht-----
> Von: Felipe Schnack [mailto:[EMAIL PROTECTED]] 
> Gesendet: Dienstag, 14. Januar 2003 11:38
> An: Tomcat Users List
> Betreff: file name
> 
> 
>   I have a servlet that generates pdf files on the fly
>   but when the browser opens the "save as..." dialog, the suggested
> default filename is my servlet's URL... I would like it to suggest
> another file name, how can i do that?
> 
> -- 
> 
> Felipe Schnack
> Analista de Sistemas
> [EMAIL PROTECTED]
> Cel.: (51)91287530
> Linux Counter #281893
> 
> Centro Universit�rio Ritter dos Reis
> http://www.ritterdosreis.br
> [EMAIL PROTECTED]
> Fone/Fax.: (51)32303341
> 
> 
> --
> To unsubscribe, e-mail:   
> <mailto:tomcat-user-> [EMAIL PROTECTED]>
> For 
> additional commands, 
> e-mail: <mailto:[EMAIL PROTECTED]>
> 


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to