File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes CREATING FILE FROM SERVLET Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "CREATING FILE FROM SERVLET" Watch "CREATING FILE FROM SERVLET" New topic
Author

CREATING FILE FROM SERVLET

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I have a servlet which throws an HTML page with a button "Save this page as Text". If the user clicks on the button, I want to create a file in the user's computer and write some data.
How do I achieve this?
Jesse Tilly
Ranch Hand

Joined: Jun 25, 2000
Posts: 37
A couple of ways. The button could trigger JavaScript that requests a file you've created server-side. The user will be asked if it's okay to save/run it. The button could also POST to a servlet that "responds" as a file rather than as HTML. The browser will handle it according to its MIME settings. Or, the button could trigger JavaScript that makes the servlet request generating a dynamic filestream (no messy temp files).
Jesse
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thankx for your prompt reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CREATING FILE FROM SERVLET