Challenges master! ! ! ! Partakers caught answer

Category: Web Develop
2011-07-22 03:04:16

Sponsored Links
How to download files, the name corresponding to the change?
Request is this:
where control is the name of the servlet, which according to id query the database or file, and then write to the client, the problem lies in the client Save the file can not be saved in the correct file name, that every time you are prompted to save the control.
My idea is to play according to their own name to save the file?
how ah?
I used setcontentype ("appliction / x, name = xxx") but no effect

Sponsored Links

2011-07-22 03:22:35
InputStream is = null;

int i = is.available ();

/ / set the parameters so that the browser pop-up download window
response.setContentType ("application / octet-stream") ;
response.setHeader ("Accept-Ranges", "bytes");
response.setHeader ("Accept- Length ", (new Integer (i)). toString ());
response.setHeader (" Content-Disposition "," attachment; filename = " + getFileName (fileURL));

/ / read the stream and sent to the client
byte [] bytes = new byte [4096];
int length = -1;
while (( length = (bytes))! = -1) {
/ / here is ServletOutputStream object used to send flow information
response.getOutputStream (). write (bytes, 0, length);
is.close ();

need to explain to speak
2011-07-22 03:31:20
Thanks! Flying thoughts
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.