Sh_Rashed
asked on
downloading file to user machine
Hi experts,
I have mp3 files in the server and I have jsp page that display all these files. I need when the user click on the "save", the file is downloaded to his machine.
Thanks
I have mp3 files in the server and I have jsp page that display all these files. I need when the user click on the "save", the file is downloaded to his machine.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have tried the code in the url
System.out.println("My file is:111111111111111111"+req uest.getPa rameter("f ile"));
String filename = request.getParameter("file ");
String original_file = "/CourseFiles"+filename;
File f = new File(filename);
int length = 0;
ServletOutputStream op = response.getOutputStream() ;
ServletContext context = getServletConfig().getServ letContext ();
String mimetype = context.getMimeType( filename );
response.setContentType( (mimetype != null) ? mimetype : "application/octet-stream" );
response.setContentLength( (int)f.length() );
response.setHeader( "Content-Disposition", "attachement; filename=\"" + original_file+ "\"" );
byte[] bbuf = new byte[1000];
DataInputStream in = new DataInputStream(new FileInputStream(f));
while ((in != null) && ((length = in.read(bbuf)) != -1))
{
op.write(bbuf,0,length);
}
in.close();
op.flush();
op.close();
but I got this Exception 1.mp3 (The system cannot find the file specified)
the file I want to download it is mps file audio
System.out.println("My file is:111111111111111111"+req
String filename = request.getParameter("file
String original_file = "/CourseFiles"+filename;
File f = new File(filename);
int length = 0;
ServletOutputStream op = response.getOutputStream()
ServletContext context = getServletConfig().getServ
String mimetype = context.getMimeType( filename );
response.setContentType( (mimetype != null) ? mimetype : "application/octet-stream"
response.setContentLength(
response.setHeader( "Content-Disposition", "attachement; filename=\"" + original_file+ "\"" );
byte[] bbuf = new byte[1000];
DataInputStream in = new DataInputStream(new FileInputStream(f));
while ((in != null) && ((length = in.read(bbuf)) != -1))
{
op.write(bbuf,0,length);
}
in.close();
op.flush();
op.close();
but I got this Exception 1.mp3 (The system cannot find the file specified)
the file I want to download it is mps file audio
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank u so much
ASKER
it works fine in firefox, but not in IE7?
help plz? :)
help plz? :)
what error you are getting??
ASKER
the quicktime plugin in the IE7 shows question mark image
instead of opening up directly to quicktime, save to the disc and then run it with quicktime to see if the file is coming down correctly
Then the quicktime plugin is not properly configured with IE.
ASKER
but when I open the url of mp3 in IE, quicktime plays the file.
anyway, Thanks for helping me :)
anyway, Thanks for helping me :)
>> response.setHeader( "Content-Disposition", "attachement; filename=\"" + original_file+ "\"" );
attach'E'ment with an extra E in between or attachment? I guess that is the issue. One of the versions of IE had this bug, not sure which one.
attach'E'ment with an extra E in between or attachment? I guess that is the issue. One of the versions of IE had this bug, not sure which one.
<a href="yourfile">Filename</