• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display a "save as" dialog

 
Ste Lamb
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is probably very easy to do but I can't find a way to do it.
I have some information displayed on a JSP which I want to save to a simple text file.
On selecting a button I want it bring up the "save as" dialog where the user can decide where to save the file to on their local machine. I can create the file and put data into it in Java, but I can't work out how to bring up the save as dialog from the JSP.
Any help much appreciated! Also any good resources for this sort of thing would also be appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no standards-compliant method to do this that will work across all browsers. I wouldn't be surprised if there were an IE-only way to do this in that browser, but I wouldn't know. If this is the route that you wish to take, perhaps the HTML/Javascript forum would be a good place to further pursue this.
But I'd say that a better way to do this would be for your button to post a request to a servlet that would set the content type of the response to text and specify it as an 'attachment' (search these forums for this term for exact syntax examples) and then outputs the data in whatever text-only format is approriate.
This should cause the download dialog of the browser to open to allow the user to save the text file to disk.
hth,
bear
 
Ste Lamb
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear thanks for your response.
I had finally worked it out using the method you suggest - although I'm requesting the info from another JSP. How would I reference a servlet directly?
Thanks for your response though, it doesn't seem to be documented anywhere that this is the way to do it.. altohugh more likely I was searching in the wrong place!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic