download a file to particular location in client s

2019-05-25 08:47发布

Below is the code i've written i've to download a file, Now I need to download the file to particular location in client system.I'll get the path through input from the user. I know it's not good to mess client system but I had to do that

        //setting the content type of response
        response.setContentType("application/"+strFileType);

        response.setHeader("content-disposition","attachment; filename="+strFileName+"."+strFileType);

        //creating a file input stream object
         InputStream input = blob.getBinaryStream();

         //declaring a variable
         int i;
         while((i=input.read())!=-1)
         {
             //writing output
             printWriter.write(i);
         }

         //closing the streams
         input.close();
         printWriter.close();

3条回答
\"骚年 ilove
2楼-- · 2019-05-25 08:51
Bombasti
3楼-- · 2019-05-25 09:05

I know it's not good to mess client system but I had to do that ....

Well the good news (from the user's perspective!) is that you can't do it. Even if you "have to". A web browser is built specifically to stop you (the server side) from doing that kind of thing.

The only away around this is to implement the functionality in a TRUSTED browser plugin or applet or something that the user has to specifically install on his / her machine.


... where to use the path taken from the user and i'm programming this just like ftp but server side is a database

The problem is that the browser has NO WAY to judge whether you are doing this for legitimate purposes ... or as an attempt to clobber system / user files, plant malware or any number of other things that may be harmful to the user.

It ain't going to take the risk of letting you do it, and that is a GOOD THING.

查看更多
兄弟一词,经得起流年.
4楼-- · 2019-05-25 09:14

If you are inside an intranet and can trust a server, use an applet or similar technolofgies with granted access privileges... but once again this is REALLY bad.

查看更多
登录 后发表回答