File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrting Response?

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have raw bytes which i want to write to the response(these raw bytes are contents fo a file).I want to write these bytes to a particular location (say a file) on the machine from which my servlet got the request.

So how can i do that??

Jignesh
[ April 06, 2006: Message edited by: Bear Bibeault ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the response is sent to he client, if they want they can save it to the file system. If they choose not to there is nothing you can do about it. The client saves it where they want, you have no control over this and cannot suggest locations or affect it in any way. You can't even specify a default save location.

Dave
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David.

What would be the content type to be set, for sending the .xls file content , to the response.

And when user will get the option to save the content would it be by default get saved as .xls file???.Because i want that the user obtains the same xls file format generated on my server in their local machine as an xls file.

Jignesh
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the thread here for both
[ April 05, 2006: Message edited by: David O'Meara ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also an example page in the JSP Faq that does something similar.
It sends characters instead of bytes but the process for setting up the response headers is the same.

http://faq.javaranch.com/view?JspAndExcel
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies.

I am able to download & save the files as excel files.The browser automatically opens my stream content with the excel as it is already installed on my machine.

But some problems i am facing are as follows:

1) When i save the file & then try to open that saved file the OS doesn't allows me to do taht .It says already a file with the filename which i have given to my saved file is open.So i have navigate back into my application then i am able to view that file.

But sometimes, after navigating back also i am not able to view the file i am able to view just the Microsofts Excel Application's Menu & its footer but not the content of my file.

When i analysed the problem i found that even after navigating back in the application an instance of EXCEL.exe remains active in the taskManager.That it doesn't get killed.Finally when i close my application i am able to view the file properly.


2) When i have a single file i am able to download & save it easily.But in some cases i have mutiple files to be downloaded & saved so how can i do this thing of downloading & saving multiple files coming in the response.

Here is my code for downlaoding my reports:

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first query is solved Kindly help me sort out my second query of downloading multiple files.

Also i am not able to delete my file on the server after downloading it .
Jignesh
[ April 06, 2006: Message edited by: Jignesh Gohel ]
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jignesh Gohel:
Also i am not able to delete my file on the server after downloading it .
This is why:That's a comment, it doesn't close the stream. At least on Windows machines, you can't delete a file that still has open streams attached to it.

As for including multiple files in a response: package them in a zip file or something.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic