File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Downloadinf a file from server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Downloadinf a file from server" Watch "Downloadinf a file from server" New topic

Downloadinf a file from server

madupathi arun

Joined: Feb 25, 2008
Posts: 23

i am having folowing problem

I need to take the user specific directory and pass that to servlet file

I am calling document.execCommand('SaveAs','1','filename.xml'); on the click of download button

but I was unable to pass that file directory using this
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

How are you writing this DHTML out? Can you show us your servlet code?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
madupathi arun

Joined: Feb 25, 2008
Posts: 23

my requirement is to show saveas dialogue when i clickm on download button
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

What a browser does when a file of a certain type is sent to it by the server depends on the Content-Type HTTP header that's in the response.

If Content-Type is set to "text/xml", then the browser will probably display it as an XML file.

If the Content-Type is set to something that the browser doesn't recognise, then it will offer the user a Save As dialog box. If you set the Content-Type to "application/octet-stream" (which means: this is generic data), then it will most likely show you the Save As dialog box.

So what you need to do is set the Content-Type HTTP header of the response before you send back the file from your servlet.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Downloadinf a file from server
It's not a secret anymore!