• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Outputting to .txt

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers ,

I have a page which has a Table which has details like name , password , address , telephone number etc...

Now this is displayed from the database nicely as i want to. Now i have a button saying EXPORT to .txt , Whatever data it shows on the Jsp i.e name,, password , address , telephone number etc on click of that button should popup an option to the user giving him / her an option to save the data as .txt file. I have tried response.setContentType(text/plain) and setting the header to .txt button , the file which is opening is outputting the source of the html page then the output which i am desiring i.e name , username etc.

Can someone please show me the light on how this can be achieved. Previously it was application/vnd.ms-excel and it used to save in excel , but now the users need it into a .txt rather then .xls.

Any help is much appreciated.

Thanks in advance.

Yogendra N Joshi
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your action:
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello thanks for the code, I have tried to put it.

It giving an exception saying method getFileByteArrayOutputStream(); cannot be resolved to a type. I have seen the API for ByteArrayOutputStream but didn't get any fruits out of it.

The Current code is :



For the extension which we are using right now . i.e doc , its coming very perfectly. Also if the extension is .xls then its coming fine. Only for .txt it is giving problems. Can you please give us more idea on this ?

Thanks again.
Yogendra
[ November 03, 2006: Message edited by: Yogendra Joshi ]
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getFileByteArrayOutputStream() is method I made up.

Replace it with a ByteArrayOutputStream of the txt file you want to display.
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Dom ,

Thanks for the immediate reply.

I think the getFileByteArrayOutputStream which you made up for you would work for me as well.. Can you post that too ?

Thanks

Yogendra
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just made up the method name.

If you tell me where you're getting the text file from (disk, string, etc..) I can help you convert it to an output stream.
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a String, here is how to get an output stream:



I'm not sure if this will work because I haven't tested it or tried to complie it, but it shouldn't be too far off.
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic