• Post Reply Bookmark Topic Watch Topic
  • New Topic

servlet response with csv file  RSS feed

 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering whether it is possible to send a csv file as a response from a servlet without actually creating/storing it on the server.

The way I have solved it at the moment is that whenever i get a request from the client a create the file on the server and it is stored on the HD on the server. Then it is sent as a response.



Is it possible to create and send a csv file as a response "on the fly" rather than creating the file on the HD?


Thanks for any advice and help.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure it's possible. Using the getWriter method instead of the getOutputStream method you can write any text you wish as the response.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer , Is passing java.io.File as return type is possible with java ??
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean a method that returns an object of type File (java.io.File)?

That is possible.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can stream the contents of any file you wish, text or binary, provided your code handles it correctly. But I thought the goal was to NOT have a file?
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that right. I solved it so that the output is streamed to the reponse without using a file, thanks.

I replied to the other post, sorry for the confusion.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!