Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Wrting Response? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Wrting Response?" Watch "Wrting Response?" New topic
Author

Wrting Response?

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
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 ]

Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Dec 28, 2004
Posts: 276
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

Joined: Mar 06, 2001
Posts: 13459

Check the thread here for both
[ April 05, 2006: Message edited by: David O'Meara ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
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

Joined: Dec 28, 2004
Posts: 276
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
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

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
 
subject: Wrting Response?