Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Satish Dhamodharam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Satish Dhamodharam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic