• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic