The moose likes Servlets and the fly likes Servlet responding with Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet responding with "application/x-gzip", set filename?" Watch "Servlet responding with "application/x-gzip", set filename?" New topic
Author

Servlet responding with "application/x-gzip", set filename?

Satish Dhamodharam
Greenhorn

Joined: Mar 02, 2001
Posts: 4
I am writing a servlet which will provide a customized downloaded jar file (with a class compiled and added which times out 15 days after current date)
I send back the jar file through the ServletOutputStream, and the browser asks me whether to open or save. When I specify "save", it saves it to the same filename as the referring page, "Download.html" also with the sessionID, which was where I pressed the button which led to the GET request being sent to the servlet!
How do I set the file name in the servlet's response?
Thanks!

------------------
Satish k.dhamodharam


Satish k.dhamodharam
Phil Hanna
Ranch Hand

Joined: Apr 05, 2001
Posts: 118
It's browser dependent, but basically you need to send back a
Content-Disposition: attachment; filename="myfile.jar"
header. That's good enough for Netscape; Internet Explorer still doesn't get it right unless the URL that requests the servlet ends with ".jar". You can have your HTML form append a dummy filename ending with ".jar" at the end of your servlet invocation URL.
------------------
Phil Hanna
Sun Certified Programmer for the Java 2 Platform
Author of :
JSP: The Complete Reference
Instant Java Servlets
Website: http://www.philhanna.com


Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
Satish Dhamodharam
Greenhorn

Joined: Mar 02, 2001
Posts: 4
Originally posted by Phil Hanna:
It's browser dependent, but basically you need to send back a
Content-Disposition: attachment; filename="myfile.jar"
header. That's good enough for Netscape; Internet Explorer still doesn't get it right unless the URL that requests the servlet ends with ".jar". You can have your HTML form append a dummy filename ending with ".jar" at the end of your servlet invocation URL.


Hi Hanna,
As U said, I just tried by ur method and it works very well with netscape, but in the case of Internet Explorer, if I want to download, various file with various extensions, like ".txt", ".jar", ".exe"...
I just gave as
<form Action=""/DownloadServlet?dummy="+<%=safe.filename%>">
where "safe.fileName" has the corresponding fileName, but this is not working...
is there anyway to overcome this problem....
regards,
Satissshhh!!!...
------------------
Satish k.dhamodharam
[This message has been edited by Satish Dhamodharam (edited May 21, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet responding with "application/x-gzip", set filename?