Re: Setting the name of a downloaded file
public class FileDownloadServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest p_request,
HttpServletResponse p_response)
throws ServletException, IOException
{
String filename = /* ... */;
File file = /* ... */;
long length = file.length();
FileInputStream fis = new FileInputStream(file);
p_response.addHeader("Content-Disposition",
"attachment; filename=\"" + filename +
"\"");
p_response.setContentType("application/octet-stream");
if (length > 0 && length <= Integer.MAX_VALUE);
p_response.setContentLength((int)length);
ServletOutputStream out = p_response.getOutputStream();
p_response.setBufferSize(32768);
int bufSize = p_response.getBufferSize();
byte[] buffer = new byte[bufSize];
BufferedInputStream bis = new BufferedInputStream(fis,
bufSize);
int bytes;
while ((bytes = bis.read(buffer, 0, bufSize)) >= 0)
out.write(buffer, 0, bytes);
bis.close();
fis.close();
out.flush();
out.close();
}
}
On Feb 11, 9:12 am, Greg Dougherty <dougherty.greg...@mayo.edu> wrote:
> So I have a way to get a "Save As" Dialog box to come up for the file
> I'm downloading from my servlet (user hits the "Export" Button, I
> create an invisible frame that points to my servlet with the
> parameters necessary for the servlet to generate the export file).
> Unfortunately, the file comes up with the name of my servlet.
>
> How do I give the Save As Dialog a better default name for the file?
> The file is generated on the fly, so putting a file name in the URL
> wouldn't work.
>
> TIA,
>
> Greg
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home